@docsector/docsector-reader 3.1.0 → 3.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/README.md CHANGED
@@ -43,6 +43,7 @@ Transform Markdown content into beautiful, navigable documentation sites — wit
43
43
  - 📝 **Markdown Rendering** — Write docs in Markdown, rendered with syntax highlighting (Prism.js)
44
44
  - 🧱 **Raw HTML in Markdown** — Renders inline and block HTML tags inside markdown sections (including homepage remote README content)
45
45
  - 🧩 **Mermaid Diagrams** — Native support for fenced ` ```mermaid ` blocks, with automatic dark/light theme switching
46
+ - ➗ **Math & KaTeX** — Native support for inline `$...$` and display `$$...$$` formulas rendered with KaTeX
46
47
  - 🚨 **GitHub-Style Alerts** — Native support for `[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]`, and `[!CAUTION]`
47
48
  - 🌍 **Internationalization (i18n)** — Multi-language support with HJSON locale files and per-page translations
48
49
  - 🌗 **Dark/Light Mode** — Automatic theme switching with Quasar Dark Plugin
package/bin/docsector.js CHANGED
@@ -23,7 +23,7 @@ const packageRoot = resolve(__dirname, '..')
23
23
  const args = process.argv.slice(2)
24
24
  const command = args[0]
25
25
 
26
- const VERSION = '3.1.0'
26
+ const VERSION = '3.2.0'
27
27
 
28
28
  const HELP = `
29
29
  Docsector Reader v${VERSION}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsector/docsector-reader",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "A documentation rendering engine built with Vue 3, Quasar v2 and Vite. Transform Markdown into beautiful, navigable documentation sites.",
5
5
  "productName": "Docsector Reader",
6
6
  "author": "Rodrigo de Araujo Vieira",
@@ -70,8 +70,10 @@
70
70
  "axios": "^1.7.7",
71
71
  "core-js": "^3.6.5",
72
72
  "hjson": "^3.2.2",
73
+ "katex": "^0.17.0",
73
74
  "markdown-it": "^13.0.1",
74
75
  "markdown-it-attrs": "^4.1.6",
76
+ "markdown-it-texmath": "^1.0.0",
75
77
  "mermaid": "^11.0.0",
76
78
  "prismjs": "^1.27.0",
77
79
  "q-colorize-mixin": "^2.0.0-alpha.5"
@@ -1,5 +1,7 @@
1
1
  import MarkdownIt from 'markdown-it'
2
2
  import attrs from 'markdown-it-attrs'
3
+ import katex from 'katex'
4
+ import texmath from 'markdown-it-texmath'
3
5
 
4
6
  const ALERT_MESSAGE_TYPES = new Set([
5
7
  'note',
@@ -12,6 +14,10 @@ const ALERT_MESSAGE_TYPES = new Set([
12
14
  const QUICK_LINKS_MARKER_PREFIX = '@@DOCSECTOR_QUICK_LINKS_'
13
15
  const EXPANDABLE_MARKER_PREFIX = '@@DOCSECTOR_EXPANDABLE_'
14
16
  const CODE_SEGMENT_MARKER_PREFIX = '@@DOCSECTOR_CODE_SEGMENT_'
17
+ const MATH_KATEX_OPTIONS = {
18
+ throwOnError: false,
19
+ strict: 'ignore'
20
+ }
15
21
 
16
22
  const parseAlertMarker = (rawContent = '') => {
17
23
  const match = String(rawContent).trim().match(/^\[!\s*([A-Za-z]+)\s*\]\s*(.*)$/s)
@@ -100,7 +106,7 @@ const restoreShieldedCodeSegments = (source = '', codeSegmentsMap = new Map()) =
100
106
  let restored = String(source)
101
107
 
102
108
  codeSegmentsMap.forEach((content, marker) => {
103
- restored = restored.replaceAll(marker, content)
109
+ restored = restored.replaceAll(marker, () => content)
104
110
  })
105
111
 
106
112
  return restored
@@ -299,10 +305,24 @@ const pushSourceCodeToken = (tokens, element, parserState) => {
299
305
  })
300
306
  }
301
307
 
308
+ const installMathSupport = (markdown) => {
309
+ markdown.use(texmath, {
310
+ engine: katex,
311
+ delimiters: 'dollars',
312
+ katexOptions: MATH_KATEX_OPTIONS
313
+ })
314
+
315
+ return markdown
316
+ }
317
+
318
+ const renderBlockToken = (markdown, element, env) => {
319
+ return markdown.renderer.render([element], markdown.options, env).trim()
320
+ }
321
+
302
322
  const createMarkdownBlockParser = () => {
303
- const markdown = new MarkdownIt({
323
+ const markdown = installMathSupport(new MarkdownIt({
304
324
  html: true
305
- })
325
+ }))
306
326
 
307
327
  markdown.use(attrs, {
308
328
  leftDelimiter: ':',
@@ -314,9 +334,9 @@ const createMarkdownBlockParser = () => {
314
334
  }
315
335
 
316
336
  const createMarkdownInlineParser = () => {
317
- return new MarkdownIt({
337
+ return installMathSupport(new MarkdownIt({
318
338
  html: true
319
- })
339
+ }))
320
340
  }
321
341
 
322
342
  const normalizePageSectionSource = (source = '') => {
@@ -444,6 +464,11 @@ export const tokenizePageSectionSource = (source = '', options = {}) => {
444
464
  return
445
465
  }
446
466
 
467
+ if (element.type === 'math_block') {
468
+ blockquote.content += renderBlockToken(markdown, element, markdownEnv)
469
+ return
470
+ }
471
+
447
472
  if (element.type.endsWith('_open')) {
448
473
  appendBlockquoteTag(element, true)
449
474
  return
@@ -519,6 +544,13 @@ export const tokenizePageSectionSource = (source = '', options = {}) => {
519
544
  pushSourceCodeToken(tokens, element, parserState)
520
545
  break
521
546
 
547
+ case 'math_block':
548
+ tokens.push({
549
+ tag: 'html',
550
+ content: renderBlockToken(markdown, element, markdownEnv)
551
+ })
552
+ break
553
+
522
554
  case 'html_block':
523
555
  tokens.push({
524
556
  tag: 'html',
@@ -574,6 +606,9 @@ export const tokenizePageSectionSource = (source = '', options = {}) => {
574
606
  case 'inline':
575
607
  parent.content += element.content
576
608
  break
609
+ case 'math_block':
610
+ parent.content += renderBlockToken(markdown, element, markdownEnv)
611
+ break
577
612
  case 'html_inline':
578
613
  case 'html_block':
579
614
  parent.content += element.content
package/src/css/app.sass CHANGED
@@ -1,3 +1,5 @@
1
+ @import 'katex/dist/katex.min.css'
2
+
1
3
  /* --- Docsector Reader --- */
2
4
  @font-face
3
5
  font-family: "Fira Code Nerd Font"
@@ -187,6 +189,16 @@ body.body--dark
187
189
  display: inline
188
190
  line-height: 0.85em
189
191
 
192
+ .katex
193
+ color: inherit
194
+ max-width: 100%
195
+
196
+ .katex-display
197
+ max-width: 100%
198
+ overflow-x: auto
199
+ overflow-y: hidden
200
+ padding: 0.35rem 0.1rem
201
+
190
202
  a
191
203
  text-decoration: none
192
204
  outline: 0
@@ -61,6 +61,25 @@ You can render Mermaid diagrams using fenced blocks with the `mermaid` language
61
61
  ```
62
62
  ```mermaid
63
63
  flowchart TD
64
+ A[Start] --> B[End]
65
+ ```
66
+ ```
67
+
68
+ ### Math and TeX
69
+
70
+ Docsector supports KaTeX-style math in standard Markdown flows, including paragraphs, alerts, and expandable content.
71
+
72
+ Use single dollar delimiters for inline math such as $E = mc^2$.
73
+
74
+ Use double dollar delimiters for display math:
75
+
76
+ ```markdown
77
+ $$
78
+ \int_0^1 x^2 dx
79
+ $$
80
+ ```
81
+
82
+ Math delimiters remain literal inside inline code and fenced code blocks, so syntax examples can be documented without rendering the equation.
64
83
 
65
84
  ### GitHub Alerts
66
85
 
@@ -75,9 +94,6 @@ Docsector also supports GitHub-style alert blockquotes:
75
94
 
76
95
  Supported types are `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, and `CAUTION`.
77
96
  Regular blockquotes (without `[!TYPE]`) continue to work as normal.
78
- A[Start] --> B[End]
79
- ```
80
- ```
81
97
 
82
98
  ### Custom Attributes
83
99
 
@@ -65,6 +65,22 @@ flowchart TD
65
65
  ```
66
66
  ```
67
67
 
68
+ ### Math e TeX
69
+
70
+ O Docsector suporta fórmulas com KaTeX nos fluxos normais de Markdown, incluindo parágrafos, alertas e conteúdo expansível.
71
+
72
+ Use delimitadores com um dólar para fórmulas inline, como $E = mc^2$.
73
+
74
+ Use delimitadores com dois dólares para fórmulas em bloco:
75
+
76
+ ```markdown
77
+ $$
78
+ \int_0^1 x^2 dx
79
+ $$
80
+ ```
81
+
82
+ Os delimitadores matemáticos permanecem literais dentro de código inline e fenced code, então exemplos de sintaxe podem ser documentados sem renderizar a equação.
83
+
68
84
  ### Alertas do GitHub
69
85
 
70
86
  O Docsector tambem suporta blockquotes de alerta no estilo do GitHub: