Skip to content

Commit d122f5d

Browse files
committed
Fix contents misplacement
Fixes #6
1 parent c1d0472 commit d122f5d

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Next
4+
- Fix TOC being misplaced when non-wikitext headings are on the page.
5+
- Fixed spacing issues in output.
6+
37
## 1.3.5
48
*2024-05-12*
59
- Changed output to no longer be prettified.

src/compile.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ export function compile(dir: string = '.', config: Config = {}): void {
7272
</div>
7373
`;
7474
// Set TOC on page
75-
if (outText.includes('<toc></toc>')) outText = outText.replace('<toc></toc>', tocElem);
76-
else outText = outText.replace(/<h\d[^>]*>/, tocElem + '$&');
75+
if (outText.includes('<toc></toc>')) {
76+
// put TOC where explicitly declared
77+
outText = outText.replace('<toc></toc>', tocElem);
78+
}
79+
else {
80+
// put TOC above first auto heading
81+
outText = outText.replace(/<h[1-6] auto/, tocElem + '$&');
82+
}
7783
}
7884

7985
// Create plaintext of HTML for use as description/metadata property.

src/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function parse(data: string, config: Config = {}): Result {
321321
// Headings: ==heading==
322322
.replace(re(r`^ (=+) \s* (.+?) \s* \1 \s* $`), (_, lvl, txt) => {
323323
const linkForm = encodeURI(txt.replace(/ /g, '_').replace(/<.+?>/g, ''));
324-
return `<h${lvl.length} id="${linkForm}">${txt}</h${lvl.length}>`;
324+
return `<h${lvl.length} auto id="${linkForm}">${txt}</h${lvl.length}>`;
325325
})
326326

327327
// Bulleted list: *item

test/src/example.wiki

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{{displaytitle: Example Page}}
2-
'''Wikity''' is a very useful build tool!
2+
<h1>Example</h1>
3+
'''Wikity''' is a ''very'' useful build tool!
34

45
<div style="border:1px solid">
56
= Headings =
67
= Root =
78
== Heading ==
89
=== Subheading ===
10+
=== A [[Link Heading]] ===
911
== Broken heading ===
1012
====== Small heading ======
1113
== ''fancy'' '''heading'''! ==

0 commit comments

Comments
 (0)