@uniweb/content-writer 0.3.3 → 0.3.4
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/package.json +2 -2
- package/src/nodes.js +6 -0
- package/tests/pretitle.test.js +36 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/content-writer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "ProseMirror document structure to Markdown converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vitest": "^4.1.7",
|
|
23
|
-
"@uniweb/content-reader": "1.2.
|
|
23
|
+
"@uniweb/content-reader": "1.2.4"
|
|
24
24
|
},
|
|
25
25
|
"directories": {
|
|
26
26
|
"test": "tests"
|
package/src/nodes.js
CHANGED
|
@@ -21,6 +21,12 @@ export { serializeInsetRef }
|
|
|
21
21
|
export function serializeHeading(node) {
|
|
22
22
|
const prefix = '#'.repeat(node.attrs?.level || 1)
|
|
23
23
|
const text = serializeInlineContent(node.content)
|
|
24
|
+
// A `#>` label line (pretitle). The hash count carries the authored
|
|
25
|
+
// spelling only — `#>` and `##>` mean the same thing — so emitting the
|
|
26
|
+
// stored level keeps the file byte-identical through a round-trip.
|
|
27
|
+
if (node.attrs?.role === 'pretitle') {
|
|
28
|
+
return `${prefix}> ${text}`
|
|
29
|
+
}
|
|
24
30
|
return `${prefix} ${text}`
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `#>` label lines (pretitles) round-trip through read → write.
|
|
3
|
+
*
|
|
4
|
+
* The hash count means nothing but is preserved — an authored `##>` comes
|
|
5
|
+
* back as `##>`, so a sync never rewrites a file over a spelling choice.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, test, expect } from 'vitest'
|
|
8
|
+
import { proseMirrorToMarkdown } from '../src/index.js'
|
|
9
|
+
import { markdownToProseMirror } from '@uniweb/content-reader'
|
|
10
|
+
|
|
11
|
+
const md = s => proseMirrorToMarkdown(markdownToProseMirror(s)).trim()
|
|
12
|
+
|
|
13
|
+
describe('pretitle round-trip', () => {
|
|
14
|
+
test('#> comes back as #>', () => {
|
|
15
|
+
expect(md('#> New in v2')).toBe('#> New in v2')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('the authored hash count is preserved', () => {
|
|
19
|
+
expect(md('##> Most popular')).toBe('##> Most popular')
|
|
20
|
+
expect(md('###> Deep label')).toBe('###> Deep label')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('a label above a headline survives in place', () => {
|
|
24
|
+
const source = '#> New in v2\n\n# Build the system\n\n## Not every page'
|
|
25
|
+
expect(md(source)).toBe(source)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('inline marks inside a label survive', () => {
|
|
29
|
+
expect(md('#> New in *v2*')).toBe('#> New in *v2*')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('serialization is a fixed point', () => {
|
|
33
|
+
const once = md('##> Label')
|
|
34
|
+
expect(md(once)).toBe(once)
|
|
35
|
+
})
|
|
36
|
+
})
|