docspack 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/style.ts CHANGED
@@ -34,6 +34,11 @@ const SENTENCE_SPLIT = /(?<=[.!?])\s+/;
34
34
  /** A heading or list item starts a new unit, whatever the previous line ended with. */
35
35
  const BLOCK_START = /\n(?=\s*(?:[-*+]\s|\d+\.\s|#{1,6}\s|\|))/;
36
36
  const LONG_SENTENCE_WORDS = 40;
37
+ /**
38
+ * A word carries a letter or a digit. Stripped code leaves its punctuation behind, so counting
39
+ * everything between spaces reports an enumeration of forty code spans as a forty-word sentence.
40
+ */
41
+ const WORD = /[\p{L}\p{N}]/u;
37
42
 
38
43
  export interface FillerHit {
39
44
  readonly phrase: string;
@@ -68,7 +73,7 @@ export function findLongSentences(text: string, maxWords = LONG_SENTENCE_WORDS):
68
73
  .flatMap((block) => block.split(BLOCK_START))
69
74
  .flatMap((block) => block.split(SENTENCE_SPLIT))
70
75
  .map((sentence) => sentence.replace(/\s+/g, " ").trim())
71
- .filter((sentence) => sentence.split(" ").filter(Boolean).length > maxWords);
76
+ .filter((sentence) => sentence.split(" ").filter((word) => WORD.test(word)).length > maxWords);
72
77
  }
73
78
 
74
79
  /**
@@ -94,11 +99,16 @@ export function contentFingerprint(text: string): string {
94
99
  .trim();
95
100
  }
96
101
 
102
+ /** An authored directive, e.g. `<!-- docspack: tags=grid -->`. Metadata, not site boilerplate. */
103
+ const DIRECTIVE_LINE = /^\s*<!--\s*docspack:/i;
104
+
97
105
  /** Removes lines a documentation site wraps around its content. */
98
106
  export function stripBoilerplate(text: string): string {
99
107
  return text
100
108
  .split("\n")
101
- .filter((line) => !BOILERPLATE.some((pattern) => pattern.test(line)))
109
+ .filter(
110
+ (line) => DIRECTIVE_LINE.test(line) || !BOILERPLATE.some((pattern) => pattern.test(line)),
111
+ )
102
112
  .join("\n");
103
113
  }
104
114