@peaceroad/markdown-it-numbering-ul-regarded-as-ol 0.2.0 → 0.2.1
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 +336 -335
- package/debug/dump_listinfos.mjs +65 -0
- package/debug/dump_tokens.mjs +72 -0
- package/index.js +5 -0
- package/package.json +5 -2
- package/src/phase0-description-list.js +654 -654
- package/src/phase1-analyze.js +90 -7
- package/src/phase2-convert.js +1037 -738
- package/src/phase3-attributes.js +260 -244
- package/src/phase5-spans.js +1 -1
- package/src/phase6-attrs-migration.js +1 -1
- package/src/preprocess-literal-lists.js +776 -0
- package/src/types-utility.js +995 -991
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import MarkdownIt from 'markdown-it'
|
|
5
|
+
import { processDescriptionList } from '../src/phase0-description-list.js'
|
|
6
|
+
import { normalizeLiteralOrderedLists } from '../src/preprocess-literal-lists.js'
|
|
7
|
+
import { analyzeListStructure } from '../src/phase1-analyze.js'
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2)
|
|
10
|
+
if (args.length === 0) {
|
|
11
|
+
console.error('Usage: node debug/dump_listinfos.mjs <markdown-or-test-file> [testIndex]')
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const [inputFile, indexArg] = args
|
|
16
|
+
const filePath = path.resolve(process.cwd(), inputFile)
|
|
17
|
+
if (!fs.existsSync(filePath)) {
|
|
18
|
+
console.error(`File not found: ${filePath}`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const testIndex = indexArg ? parseInt(indexArg, 10) : 1
|
|
23
|
+
if (indexArg && Number.isNaN(testIndex)) {
|
|
24
|
+
console.error('testIndex must be a number')
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { markdown } = extractMarkdownBlock(filePath, testIndex)
|
|
29
|
+
const tokens = MarkdownIt({ html: true }).parse(markdown, {})
|
|
30
|
+
|
|
31
|
+
const opt = createDefaultOptions()
|
|
32
|
+
processDescriptionList(tokens, opt)
|
|
33
|
+
normalizeLiteralOrderedLists(tokens)
|
|
34
|
+
const listInfos = analyzeListStructure(tokens, opt)
|
|
35
|
+
|
|
36
|
+
console.log(JSON.stringify(listInfos, null, 2))
|
|
37
|
+
|
|
38
|
+
function extractMarkdownBlock(file, blockIndex) {
|
|
39
|
+
const content = fs.readFileSync(file, 'utf8')
|
|
40
|
+
if (!/\[Markdown\]/.test(content)) {
|
|
41
|
+
return { markdown: content }
|
|
42
|
+
}
|
|
43
|
+
const blocks = content.trim().split(/\r?\n*\[Markdown\]\r?\n/)
|
|
44
|
+
if (blockIndex < 1 || blockIndex >= blocks.length) {
|
|
45
|
+
console.error(`Test index ${blockIndex} is out of range (1-${blocks.length - 1})`)
|
|
46
|
+
process.exit(1)
|
|
47
|
+
}
|
|
48
|
+
const parts = blocks[blockIndex].split(/\r?\n+\[HTML[^\]]*?\]\r?\n/)
|
|
49
|
+
return { markdown: parts[0] }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createDefaultOptions() {
|
|
53
|
+
return {
|
|
54
|
+
descriptionList: false,
|
|
55
|
+
descriptionListWithDiv: false,
|
|
56
|
+
descriptionListDivClass: '',
|
|
57
|
+
unremoveUlNest: false,
|
|
58
|
+
alwaysMarkerSpan: false,
|
|
59
|
+
markerSpanClass: 'li-num',
|
|
60
|
+
hasListStyleNone: false,
|
|
61
|
+
omitMarkerMetadata: false,
|
|
62
|
+
useCounterStyle: false,
|
|
63
|
+
addMarkerStyleToClass: false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import MarkdownIt from 'markdown-it'
|
|
5
|
+
import numberingPlugin from '../index.js'
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2)
|
|
8
|
+
if (args.length === 0) {
|
|
9
|
+
console.error('Usage: node debug/dump_tokens.mjs <markdown-or-test-file> [testIndex]')
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const [inputFile, indexArg] = args
|
|
14
|
+
const filePath = path.resolve(process.cwd(), inputFile)
|
|
15
|
+
if (!fs.existsSync(filePath)) {
|
|
16
|
+
console.error(`File not found: ${filePath}`)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const testIndex = indexArg ? parseInt(indexArg, 10) : 1
|
|
21
|
+
if (indexArg && Number.isNaN(testIndex)) {
|
|
22
|
+
console.error('testIndex must be a number')
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { markdown } = extractMarkdownBlock(filePath, testIndex)
|
|
27
|
+
|
|
28
|
+
const md = MarkdownIt({ html: true }).use(numberingPlugin)
|
|
29
|
+
const rendered = md.render(markdown)
|
|
30
|
+
|
|
31
|
+
console.log('--- Markdown ---')
|
|
32
|
+
console.log(markdown)
|
|
33
|
+
console.log('--- Rendered HTML ---')
|
|
34
|
+
console.log(rendered)
|
|
35
|
+
|
|
36
|
+
console.log('--- Tokens ---')
|
|
37
|
+
const tokens = md.parse(markdown, {})
|
|
38
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
39
|
+
const tk = tokens[i]
|
|
40
|
+
const entry = {
|
|
41
|
+
i,
|
|
42
|
+
type: tk.type,
|
|
43
|
+
tag: tk.tag,
|
|
44
|
+
nesting: tk.nesting,
|
|
45
|
+
level: tk.level,
|
|
46
|
+
content: tk.content || '',
|
|
47
|
+
map: tk.map,
|
|
48
|
+
markup: tk.markup,
|
|
49
|
+
info: tk.info,
|
|
50
|
+
attrs: tk.attrs,
|
|
51
|
+
hidden: tk.hidden || false,
|
|
52
|
+
_markerInfo: tk._markerInfo || undefined,
|
|
53
|
+
_convertedFromBullet: tk._convertedFromBullet || undefined,
|
|
54
|
+
_parentIsLoose: tk._parentIsLoose || undefined,
|
|
55
|
+
_startOverride: tk._startOverride
|
|
56
|
+
}
|
|
57
|
+
console.log(JSON.stringify(entry, null, 2))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function extractMarkdownBlock(file, blockIndex) {
|
|
61
|
+
const content = fs.readFileSync(file, 'utf8')
|
|
62
|
+
if (!/\[Markdown\]/.test(content)) {
|
|
63
|
+
return { markdown: content }
|
|
64
|
+
}
|
|
65
|
+
const blocks = content.trim().split(/\r?\n*\[Markdown\]\r?\n/)
|
|
66
|
+
if (blockIndex < 1 || blockIndex >= blocks.length) {
|
|
67
|
+
console.error(`Test index ${blockIndex} is out of range (1-${blocks.length - 1})`)
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
70
|
+
const parts = blocks[blockIndex].split(/\r?\n+\[HTML[^\]]*?\]\r?\n/)
|
|
71
|
+
return { markdown: parts[0] }
|
|
72
|
+
}
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { addAttributes } from './src/phase3-attributes.js'
|
|
|
6
6
|
import { processHtmlBlocks } from './src/phase4-html-blocks.js'
|
|
7
7
|
import { generateSpans } from './src/phase5-spans.js'
|
|
8
8
|
import { moveNestedListAttributes } from './src/phase6-attrs-migration.js'
|
|
9
|
+
import { normalizeLiteralOrderedLists } from './src/preprocess-literal-lists.js'
|
|
9
10
|
|
|
10
11
|
const mditNumberingUl = (md, option) => {
|
|
11
12
|
const opt = {
|
|
@@ -19,6 +20,7 @@ const mditNumberingUl = (md, option) => {
|
|
|
19
20
|
hasListStyleNone: false, // true=add style="list-style: none;" when role="list" is used
|
|
20
21
|
omitMarkerMetadata: false, // true=omit data-marker-prefix/suffix attributes
|
|
21
22
|
useCounterStyle: false, // true=users will use @counter-style; suppress marker spans and role attr
|
|
23
|
+
addMarkerStyleToClass: false, // true=append -with-* marker style suffix to class names
|
|
22
24
|
|
|
23
25
|
// Override with user options
|
|
24
26
|
...option
|
|
@@ -39,6 +41,9 @@ const mditNumberingUl = (md, option) => {
|
|
|
39
41
|
// Convert **Term**: pattern from paragraph to bullet_list, then to dl/dt/dd
|
|
40
42
|
// Must run before Phase 1 (parsed as bullet_list)
|
|
41
43
|
processDescriptionList(tokens, opt)
|
|
44
|
+
|
|
45
|
+
// Normalize literal nested ordered lists (markdown-it only creates nested lists when they start at 1)
|
|
46
|
+
normalizeLiteralOrderedLists(tokens)
|
|
42
47
|
|
|
43
48
|
// ===== PHASE 1: List Structure Analysis =====
|
|
44
49
|
// Analyze marker detection and structure without token conversion
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-numbering-ul-regarded-as-ol",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "This markdown-it plugin regard ul element with numbering lists as ol element.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"index.js",
|
|
9
9
|
"src/",
|
|
10
|
+
"debug/",
|
|
10
11
|
"listTypes.json",
|
|
11
12
|
"README.md",
|
|
12
13
|
"LICENSE"
|
|
@@ -14,7 +15,9 @@
|
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "node test/test.js",
|
|
16
17
|
"perf": "node test/material/performance-runner.js",
|
|
17
|
-
"test:all": "npm test && npm run perf"
|
|
18
|
+
"test:all": "npm test && npm run perf",
|
|
19
|
+
"dump:tokens": "node debug/dump_tokens.mjs",
|
|
20
|
+
"dump:listinfos": "node debug/dump_listinfos.mjs"
|
|
18
21
|
},
|
|
19
22
|
"repository": "https://github.com/peaceroad/p7d-markdown-it-numbering-ul-regarded-as-ol.git",
|
|
20
23
|
"author": "peaceroad <peaceroad@gmail.com>",
|