diff options
author | dvs1 | 2025-01-22 21:01:59 +1000 |
---|---|---|
committer | dvs1 | 2025-01-22 21:01:59 +1000 |
commit | 4a435bf8ae0e9f009346d89ebc424d8884f33cea (patch) | |
tree | 5c0852c7a0bdb926db42dd5f17b168461503433a | |
parent | Typo-- (diff) | |
download | notYetAnotherWiki-4a435bf8ae0e9f009346d89ebc424d8884f33cea.zip notYetAnotherWiki-4a435bf8ae0e9f009346d89ebc424d8884f33cea.tar.gz notYetAnotherWiki-4a435bf8ae0e9f009346d89ebc424d8884f33cea.tar.bz2 notYetAnotherWiki-4a435bf8ae0e9f009346d89ebc424d8884f33cea.tar.xz |
Replace cmark-gfm and lcmark with luamark.
Plus YAR, yet another rewrite.
-rw-r--r-- | .md.md | 3 | ||||
-rw-r--r-- | INSTALL.md | 6 | ||||
-rw-r--r-- | MeTaDaTa.md | 5 | ||||
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | README.md.md | 1 | ||||
-rwxr-xr-x | SuckItFos | 9 | ||||
-rwxr-xr-x | SuckItPm | 11 | ||||
-rw-r--r-- | TODO.md | 11 | ||||
-rwxr-xr-x | notYetAnotherWiki.lua | 213 | ||||
-rw-r--r-- | testing/.md.md | 1 | ||||
-rw-r--r-- | testing/MeTaDaTa.md | 3 | ||||
-rw-r--r-- | testing/index.md | 71 | ||||
-rw-r--r-- | testing/index.md.md | 1 |
13 files changed, 200 insertions, 139 deletions
@@ -0,0 +1,3 @@ | |||
1 | sourcecode=https://sledjhamr.org/cgit/notYetAnotherWiki/ | ||
2 | pagehistory=https://sledjhamr.org/cgit/notYetAnotherWiki/log | ||
3 | feedatom=https://sledjhamr.org/cgit/notYetAnotherWiki/atom | ||
@@ -1,9 +1,7 @@ | |||
1 | # Install | 1 | # Install |
2 | 2 | ||
3 | notYetAnotherWiki uses [lcmark](https://github.com/jgm/lcmark) to parse [CommonMark](https://commonmark.org/) into HTML. You can probably install it using luarocks. lua-yaml is the YAML parsing library I test with. | 3 | notYetAnotherWiki uses [lunamark](https://github.com/jgm/lunamark) to parse [CommonMark](https://commonmark.org/) into HTML. You can probably install it using luarocks. lua-yaml is the YAML parsing library I test with. |
4 | 4 | ||
5 | You also need cmark-gfm and luajit installed. | 5 | You also need luajit installed. |
6 | 6 | ||
7 | Copy the notYetAnotherWiki.lua script to some place where you can run it from, /usr/local/bin is good. Make sure it is executable. | 7 | Copy the notYetAnotherWiki.lua script to some place where you can run it from, /usr/local/bin is good. Make sure it is executable. |
8 | |||
9 | Similar with the dumpTable.lua script, only it's a Lua library, so put it some place Lua can find it. /usr/local/share/lua is good. No need to be executable. | ||
diff --git a/MeTaDaTa.md b/MeTaDaTa.md deleted file mode 100644 index 24796a8..0000000 --- a/MeTaDaTa.md +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | --- | ||
2 | sourcecode: https://sledjhamr.org/cgit/notYetAnotherWiki/ | ||
3 | pagehistory: https://sledjhamr.org/cgit/notYetAnotherWiki/log | ||
4 | feedatom: https://sledjhamr.org/cgit/notYetAnotherWiki/atom | ||
5 | --- | ||
@@ -1,7 +1,3 @@ | |||
1 | --- | ||
2 | title: "notYetAnotherWiki" | ||
3 | --- | ||
4 | |||
5 | # notYetAnotherWiki | 1 | # notYetAnotherWiki |
6 | 2 | ||
7 | notYetAnotherWiki is not another wiki, at least not yet. It'll be much | 3 | notYetAnotherWiki is not another wiki, at least not yet. It'll be much |
diff --git a/README.md.md b/README.md.md new file mode 100644 index 0000000..bc85e8c --- /dev/null +++ b/README.md.md | |||
@@ -0,0 +1 @@ | |||
title=notYetAnotherWiki | |||
@@ -22,8 +22,6 @@ do | |||
22 | mkdir -p combined/$base | 22 | mkdir -p combined/$base |
23 | mkdir -p combined/${base}/`dirname ${file}` | 23 | mkdir -p combined/${base}/`dirname ${file}` |
24 | echo "Converting ${URL}/${base}/${file}?cover=print -> Foswiki/${base}/${file}.md" | 24 | echo "Converting ${URL}/${base}/${file}?cover=print -> Foswiki/${base}/${file}.md" |
25 | # pandoc -f html -t markdown --self-contained ${URL}/${base}/${file} >Foswiki/${base}/${file}.md | ||
26 | # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM | ||
27 | # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. | 25 | # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. |
28 | curl --silent --no-progress-meter ${URL}/${base}/${file}?cover=print -o Foswiki/${base}/${file}.HTM | 26 | curl --silent --no-progress-meter ${URL}/${base}/${file}?cover=print -o Foswiki/${base}/${file}.HTM |
29 | cp Foswiki/${base}/${file}.HTM Foswiki/${base}/${file}.HTM_ORIGINAL | 27 | cp Foswiki/${base}/${file}.HTM Foswiki/${base}/${file}.HTM_ORIGINAL |
@@ -40,13 +38,10 @@ do | |||
40 | -e 's/class="foswikiTopic"/class="FoswikiTopic"/g' \ | 38 | -e 's/class="foswikiTopic"/class="FoswikiTopic"/g' \ |
41 | -e 's/class="foswiki[[:alpha:]]*"//g' \ | 39 | -e 's/class="foswiki[[:alpha:]]*"//g' \ |
42 | -e "s/style='.*;'//g" | 40 | -e "s/style='.*;'//g" |
43 | # -e "s/style='background-color: #.*;'//g" \ | ||
44 | # -e "s/style='font-size: .*;'//g" | ||
45 | 41 | ||
46 | pandoc -f html -t commonmark_x --self-contained Foswiki//${base}/${file}.HTM >Foswiki/${base}/${file}.md | 42 | pandoc -f html -t commonmark_x --self-contained Foswiki//${base}/${file}.HTM >Foswiki/${base}/${file}.md |
47 | cp Foswiki/${base}/${file}.md Foswiki/${base}/${file}.md_ORIGINAL | 43 | cp Foswiki/${base}/${file}.md Foswiki/${base}/${file}.md_ORIGINAL |
48 | 44 | ||
49 | # csplit -ks Foswiki/${base}/${file}.md '%::: {.foswikiTopic}%' '/::: {.foswikiContentFooter}/' | ||
50 | csplit -ks Foswiki/${base}/${file}.md '%::: {.FoswikiTopic}%' '/::: {.patternInfo}/' | 45 | csplit -ks Foswiki/${base}/${file}.md '%::: {.FoswikiTopic}%' '/::: {.patternInfo}/' |
51 | if [ -f xx00 ]; then | 46 | if [ -f xx00 ]; then |
52 | rm Foswiki/${base}/${file}.md | 47 | rm Foswiki/${base}/${file}.md |
@@ -63,10 +58,6 @@ do | |||
63 | # -e 's/\{\.pattern.*//g' \ | 58 | # -e 's/\{\.pattern.*//g' \ |
64 | 59 | ||
65 | echo -e "****\n[Original page](${URL}/${base}/${file}) where maybe you can edit it." >> Foswiki/${base}/${file}.md | 60 | echo -e "****\n[Original page](${URL}/${base}/${file}) where maybe you can edit it." >> Foswiki/${base}/${file}.md |
66 | |||
67 | # pandoc -t html -f commonmark_x --self-contained Foswiki/${base}/${file}.md > Foswiki/${base}/${file}.htm | ||
68 | # cmark-gfm -t html -e footnotes -e table -e strikethrough Foswiki/${base}/${file}.md > Foswiki/${base}/${file}.body | ||
69 | # ln -frs Foswiki/${base}/${file}.body combined/${base}/${file}.body | ||
70 | ln -frs Foswiki/${base}/${file}.md combined/${base}/${file}.md | 61 | ln -frs Foswiki/${base}/${file}.md combined/${base}/${file}.md |
71 | 62 | ||
72 | if [ -f xx01 ]; then | 63 | if [ -f xx01 ]; then |
@@ -17,12 +17,9 @@ find /opt/pmwiki/wiki.d ${filter} \ | |||
17 | do | 17 | do |
18 | base=`echo "${line}" | cut -d '.' -f 1` | 18 | base=`echo "${line}" | cut -d '.' -f 1` |
19 | file=`echo "${line}" | cut -d '.' -f 2` | 19 | file=`echo "${line}" | cut -d '.' -f 2` |
20 | # page="?n=${line}" | ||
21 | mkdir -p PmWiki/$base | 20 | mkdir -p PmWiki/$base |
22 | mkdir -p combined/$base | 21 | mkdir -p combined/$base |
23 | echo "Converting ${URL}/?n=${base}.${file}?action=print -> PmWiki/${base}/${file}.md" | 22 | echo "Converting ${URL}/?n=${base}.${file}?action=print -> PmWiki/${base}/${file}.md" |
24 | # pandoc -f html -t markdown --self-contained ${URL}/?n=${base}.${file} >PmWiki/${base}/${file}.md | ||
25 | # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM | ||
26 | # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. | 23 | # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. |
27 | # curl --no-progress-meter ${URL}/?n=${base}.${file}?action=markdown -o PmWiki/${base}/${file}.MD | 24 | # curl --no-progress-meter ${URL}/?n=${base}.${file}?action=markdown -o PmWiki/${base}/${file}.MD |
28 | curl --no-progress-meter ${URL}/?n=${base}.${file}?action=print -o PmWiki/${base}/${file}.HTM | 25 | curl --no-progress-meter ${URL}/?n=${base}.${file}?action=print -o PmWiki/${base}/${file}.HTM |
@@ -45,11 +42,9 @@ do | |||
45 | -e "s/class='vspace'//g" \ | 42 | -e "s/class='vspace'//g" \ |
46 | -e "s/class='wikilink'//g" \ | 43 | -e "s/class='wikilink'//g" \ |
47 | -e "s/style='.*;'//g" | 44 | -e "s/style='.*;'//g" |
48 | # -e "s/style='background-color: #.*;'//g" \ | ||
49 | # -e "s/style='font-size: .*;'//g" | ||
50 | 45 | ||
51 | pandoc -f html -t commonmark_x --self-contained PmWiki//${base}/${file}.HTM >PmWiki/${base}/${file}.md | ||
52 | # pandoc -f markdown -t commonmark_x --self-contained PmWiki//${base}/${file}.MD >PmWiki/${base}/${file}.md | 46 | # pandoc -f markdown -t commonmark_x --self-contained PmWiki//${base}/${file}.MD >PmWiki/${base}/${file}.md |
47 | pandoc -f html -t commonmark_x --self-contained PmWiki//${base}/${file}.HTM >PmWiki/${base}/${file}.md | ||
53 | cp PmWiki/${base}/${file}.md PmWiki/${base}/${file}.md_ORIGINAL | 48 | cp PmWiki/${base}/${file}.md PmWiki/${base}/${file}.md_ORIGINAL |
54 | 49 | ||
55 | # Attempt to clean things up, badly. | 50 | # Attempt to clean things up, badly. |
@@ -68,10 +63,6 @@ do | |||
68 | 63 | ||
69 | # Don't need this, the parts we are grabbing already include that link at the bottom. | 64 | # Don't need this, the parts we are grabbing already include that link at the bottom. |
70 | # echo -e "****\n[Original page](${URL}/${base}/${page}) where maybe you can edit it." >> PmWiki/${base}/${file}.md | 65 | # echo -e "****\n[Original page](${URL}/${base}/${page}) where maybe you can edit it." >> PmWiki/${base}/${file}.md |
71 | |||
72 | # pandoc -t html -f commonmark_x --self-contained PmWiki/${base}/${file}.md > PmWiki/${base}/${file}.htm | ||
73 | # cmark-gfm -t html -e footnotes -e table -e strikethrough PmWiki/${base}/${file}.md > PmWiki/${base}/${file}.body | ||
74 | # ln -frs PmWiki/${base}/${file}.body combined/${base}/${file}.body | ||
75 | ln -frs PmWiki/${base}/${file}.md combined/${base}/${file}.md | 66 | ln -frs PmWiki/${base}/${file}.md combined/${base}/${file}.md |
76 | 67 | ||
77 | if [ -f xx01 ]; then | 68 | if [ -f xx01 ]; then |
@@ -3,10 +3,9 @@ | |||
3 | ## Do these | 3 | ## Do these |
4 | 4 | ||
5 | Bugs - | 5 | Bugs - |
6 | - https://nyaw.wiki.devuan.org/users/Plentyn/WebHome.HTML has that twisty thing which looks not simple to remove. | 6 | - /users/Plentyn/WebHome.HTML has that twisty thing which looks not simple to remove. |
7 | - https://nyaw.wiki.devuan.org/users/dunno/Devuan Cluster.HTML A very lengthy and complex document, I'll likely miss something, but chip away at the obvious. | 7 | - /users/dunno/Devuan Cluster.HTML A very lengthy and complex document, I'll likely miss something, but chip away at the obvious. |
8 | - https://nyaw.wiki.devuan.org/users/Debdog.HTML pandoc can't handle the background table cell colours in the "Background colours" table, which is kinda the point of it. | 8 | - /users/Debdog.HTML pandoc can't handle the background table cell colours in the "Background colours" table, which is kinda the point of it. |
9 | - {.underline} is the result of <strong>foo</strong> getting lost in translation. | ||
10 | - PmWiki in it's current config needs that ?n=foo.bar nonsense for the Original page link. Which I'm currently neatly sidestepping, the scraped page has a similar thing. | 9 | - PmWiki in it's current config needs that ?n=foo.bar nonsense for the Original page link. Which I'm currently neatly sidestepping, the scraped page has a similar thing. |
11 | 10 | ||
12 | Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version. | 11 | Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version. |
@@ -37,9 +36,6 @@ Extract title from Fos and Pm, maybe even pagetitle if possible. Title is point | |||
37 | 36 | ||
38 | htmx | 37 | htmx |
39 | 38 | ||
40 | pandoc replacements | ||
41 | - cmark-gfm | ||
42 | |||
43 | cgit has Lua | 39 | cgit has Lua |
44 | 40 | ||
45 | 41 | ||
@@ -49,6 +45,7 @@ cgit has Lua | |||
49 | Reuse the user system from SledjChisl. | 45 | Reuse the user system from SledjChisl. |
50 | 46 | ||
51 | levels - | 47 | levels - |
48 | |||
52 | - banned | 49 | - banned |
53 | - reader | 50 | - reader |
54 | - member | 51 | - member |
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 7268170..8c9a5c9 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -2,13 +2,63 @@ | |||
2 | 2 | ||
3 | -- Read the README file for what this is all about. If there is no README or similar, then you can find the link to the source below. | 3 | -- Read the README file for what this is all about. If there is no README or similar, then you can find the link to the source below. |
4 | 4 | ||
5 | local lcmark = require("lcmark") -- https://github.com/jgm/lcmark | 5 | local lunamark = require("lunamark") -- https://github.com/jgm/lunamark |
6 | |||
7 | local opts = { | ||
8 | layout='compact', | ||
9 | -- This list is copied from the lunamark source code, until I discover a way to discover it. The descriptions are useful to. | ||
10 | containers=false, -- Put sections in containers (e.g. div or section tags) | ||
11 | slides=false, -- Like containers, but do not nest them | ||
12 | startnum=true, -- Start number of an ordered list is significant | ||
13 | smart=false, -- Smart typography (quotes, dashes, ellipses) | ||
14 | preserve_tabs=true, -- Don't expand tabs to spaces | ||
15 | notes=true, -- Footnotes | ||
16 | inline_notes=true, -- Inline footnotes | ||
17 | definition_lists=true, -- Definition lists | ||
18 | citations=true, -- Citations | ||
19 | citation_nbsps=true, -- Turn spacing into non-breaking spaces in citations | ||
20 | fenced_code_blocks=true, -- Fenced code blocks | ||
21 | lua_metadata=true, -- Lua metadata | ||
22 | pandoc_title_blocks=true, -- Pandoc style title blocks | ||
23 | hash_enumerators=true, -- may be used as ordered list enumerator | ||
24 | require_blank_before_blockquote=false, | ||
25 | require_blank_before_header=false, | ||
26 | require_blank_before_fenced_code_block=false, | ||
27 | fancy_lists=true, -- Pandoc style fancy lists | ||
28 | task_list=true, -- GitHub-Flavored Markdown task list | ||
29 | strikeout=true, -- Strike-through with double tildes | ||
30 | mark=true, -- Highlight with double equals | ||
31 | subscript=true, -- Subscripted text between tildes | ||
32 | superscript=true, -- Superscripted text between circumflexes | ||
33 | bracketed_spans=true, -- Spans with attributes | ||
34 | fenced_divs=true, -- Divs with attributes | ||
35 | raw_attribute=true, -- Raw pass-through on code elements | ||
36 | fenced_code_attributes=true, -- Fenced code block attributes | ||
37 | link_attributes=true, -- Link attributes | ||
38 | pipe_tables=true, -- PHP Markdown Extra pipe table support | ||
39 | table_captions=true, -- Table caption syntax extension | ||
40 | header_attributes=true, -- Header attributes | ||
41 | line_blocks=true, -- Line blocks | ||
42 | escaped_line_breaks=true, -- Pandoc-style escaped hard line breaks | ||
43 | } | ||
44 | local writer = lunamark.writer.html5.new(opts) | ||
45 | local template = '' | ||
46 | local h = io.open("default.template", 'r') | ||
47 | if nil ~= h then | ||
48 | template = h:read('*a') | ||
49 | h:close() | ||
50 | else | ||
51 | print('oops! No such file ' .. 'default.template') | ||
52 | end | ||
53 | -- Can override the various writer functions, there's something for each of the basic HTML elements. | ||
54 | -- Override anything that's generic. | ||
55 | local parse = lunamark.reader.markdown.new(writer, opts) | ||
6 | 56 | ||
7 | 57 | ||
8 | 58 | ||
9 | -- Some global data. | 59 | -- Some global data. |
10 | local globalData = { | 60 | local globalData = { |
11 | ['_'] = ' ', ['dlr'] = '$', | 61 | ['s'] = ' ', ['_'] = ' ', ['dlr'] = '$', |
12 | ['devuanCinnabarDark'] = '#310202', ['devuanCinnabarLight'] = '#510505', | 62 | ['devuanCinnabarDark'] = '#310202', ['devuanCinnabarLight'] = '#510505', |
13 | ['devuanDarkPurpyDark'] = '#33313b', ['devuanDarkPurpyLight'] = '#3c3a45', | 63 | ['devuanDarkPurpyDark'] = '#33313b', ['devuanDarkPurpyLight'] = '#3c3a45', |
14 | ['devuanDeepSeaDark'] = '#132f40', ['devuanDeepSeaLight'] = '#1a4562', | 64 | ['devuanDeepSeaDark'] = '#132f40', ['devuanDeepSeaLight'] = '#1a4562', |
@@ -23,7 +73,7 @@ local Sites, Files, Subs = {}, {}, {} | |||
23 | 73 | ||
24 | -- Useful functions, part 0. | 74 | -- Useful functions, part 0. |
25 | 75 | ||
26 | -- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applaid to the former. | 76 | -- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applied to the former. |
27 | local derefiTable = function(t, strip) | 77 | local derefiTable = function(t, strip) |
28 | local argh = {} | 78 | local argh = {} |
29 | for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end | 79 | for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end |
@@ -50,29 +100,47 @@ local stringBits = function(l) | |||
50 | end | 100 | end |
51 | 101 | ||
52 | 102 | ||
103 | -- Put a value into the Files or Subs table, creating things if needed. | ||
104 | local toFile = function(name, key, value) | ||
105 | if nil == Files[name] then Files[name] = {} end | ||
106 | if nil ~= key then Files[name][key] = value end | ||
107 | for i, v in ipairs{'metadata', 'bits', } do | ||
108 | if nil == Files[name][v] then Files[name][v] = {} end | ||
109 | end | ||
110 | end | ||
111 | local toSub = function(name, key, value) | ||
112 | if nil == Subs[name] then Subs[name] = {} end | ||
113 | if nil ~= key then Subs[name][key] = value end | ||
114 | for i, v in ipairs{'metadata', 'bits', 'files', 'subs'} do | ||
115 | if nil == Subs[name][v] then Subs[name][v] = {} end | ||
116 | end | ||
117 | end | ||
118 | |||
119 | |||
53 | 120 | ||
54 | -- Actually start doing things. | 121 | -- Actually start doing things. |
55 | 122 | ||
56 | -- Scan the subdirectories looking for .md files. | 123 | -- Scan the subdirectories looking for .md files. |
57 | local directory = arg[1] | 124 | local directory = arg[1] |
125 | toSub('') --Subs[''] = {files = {}, subs = {}, bits = {}} | ||
58 | if nil == directory then directory = '.' end | 126 | if nil == directory then directory = '.' end |
59 | if '.' ~= directory then | 127 | if '.' ~= directory then |
60 | for l in io.popen('find . -name "*.md" -type f,l -printf "%P\n"'):lines() do | 128 | for l in io.popen('find . -name "*.md" -type f,l -printf "%P\n"'):lines() do |
61 | Files[string.gsub(l, '%.md$', '')] = {} | 129 | toFile(string.gsub(l, '%.md$', '')) |
62 | end | 130 | end |
63 | end | 131 | end |
64 | -- Can add in a distant directory to, for putting it's results in the current directory. | 132 | -- Can add in a distant directory to, for putting it's results in the current directory. |
65 | for l in io.popen('find ' .. directory .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do | 133 | for l in io.popen('find ' .. directory .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do |
66 | local n = string.gsub(l, '%.md$', '') | 134 | local n = string.gsub(l, '%.md$', '') |
67 | if nil == Files[n] then Files[n] = {} end | 135 | if nil == Files[n] then toFile(n) end |
68 | end | 136 | end |
69 | 137 | ||
70 | -- Gotta figure out all the files and subs first. File and sub metadata comes along for the ride. | 138 | -- Gotta figure out all the files and subs first. File and sub metadata comes along for the ride. |
71 | Subs[''] = {files = {}, subs = {}, bits = {}} | ||
72 | for name, file in pairs(Files) do | 139 | for name, file in pairs(Files) do |
73 | local bitter, path = '', '' | 140 | local bitter, path = '', '' |
74 | local bits, bit = stringBits(name) | 141 | local bits, bit = stringBits(name) |
75 | local ln = #bits | 142 | local ln = #bits |
143 | local body, metadata = '', {} | ||
76 | 144 | ||
77 | -- Go through our bits, construct Subs with bits. | 145 | -- Go through our bits, construct Subs with bits. |
78 | Files[name].bits = bits | 146 | Files[name].bits = bits |
@@ -82,41 +150,61 @@ for name, file in pairs(Files) do | |||
82 | for i, d in ipairs(bits) do | 150 | for i, d in ipairs(bits) do |
83 | if '' ~= path then path = path .. '/' end | 151 | if '' ~= path then path = path .. '/' end |
84 | path = path .. d | 152 | path = path .. d |
85 | if nil == Subs[path] then Subs[path] = {files = {}, subs = {}} end | 153 | toSub(path, 'bits', derefiTable(bits, true)) |
86 | if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end | 154 | if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end |
87 | Subs[path].bits = derefiTable(bits, true) | ||
88 | if i < ln then table.remove(Subs[path].bits, #bits) end | 155 | if i < ln then table.remove(Subs[path].bits, #bits) end |
89 | end | 156 | end |
90 | 157 | ||
91 | -- Start the file parsing here, coz we need it's metadata. | 158 | if '.md' == string.sub(name, -3, -1) then |
92 | -- print('Parsing ' .. name .. '.md') | 159 | -- This is a metadata only file, no content, stash the matadata. |
93 | local h = io.open(name .. '.md', 'r') | 160 | for l in io.open(name .. '.md'):lines() do |
94 | -- TODO - should bail here on error? | 161 | for k, v in string.gmatch(l, "(%w+)%s*=%s*(.+)") do metadata[k] = v end |
95 | if nil ~= h then file.cm = h:read('*a') ; h:close() else print('oops! No such name ' .. name) end | 162 | end |
96 | -- Convert the CommonMark to HTML, including the metadata. | 163 | if '.md' == name then toSub(path, 'metadata', metadata) |
97 | local body, metadata, err = lcmark.convert(file.cm, "html", {smart = true, yaml_metadata = true, columns = 0}) | 164 | elseif '/.md' == string.sub(name, -4, -1) then toSub(path, 'metadata', metadata) |
98 | if nil == body then print('oops! ' .. err) | 165 | else toFile(string.sub(name, 1, -4), 'metadata', metadata) |
99 | elseif '' == body then | 166 | end |
100 | -- This is a metadata only file, no content, stash the matadata in it's directory. | ||
101 | Subs[path].metadata = metadata | ||
102 | Files[name] = nil | 167 | Files[name] = nil |
103 | else | 168 | else |
104 | -- Ordinary md file, stash it's metadata and parsed body. | 169 | |
105 | -- I need cmark-gfm, coz lcmark doesn't support tables and stuff, it only does basic cmark. | 170 | -- Start the file parsing here, coz we need it's metadata. |
106 | local out = '' | 171 | -- print('Parsing ' .. name .. '.md') |
107 | h = io.popen('if which cmark-gfm ; then echo "found" ; fi | tail -n 1') | 172 | h = io.open(name .. '.md', 'r') |
108 | if nil ~= h then out = h:read('*a') ; h:close() end | 173 | if nil ~= h then |
109 | if 'found\n' == out then | 174 | body = h:read('*a') ; h:close() |
110 | -- Have to strip out the metadata first, coz cmark-gfm doesn't grok that. | 175 | local f0, f1, token |
111 | h = io.popen('cp "' .. name .. '.md" "' .. name .. '02" ; csplit -ksz -f "' .. name .. '" "' .. name .. '.md" "/^---$/+1" "{1}" 2>/dev/null ; rm "' .. name .. '00" ; rm "' .. name .. '01" 2>/dev/null') | 176 | -- Deal with my typical double spaced sentence endings. |
112 | if nil ~= h then h:close() end | 177 | local result = '' |
113 | h = io.popen('cmark-gfm -t html -e footnotes -e table -e strikethrough -e autolink -e tagfilter -e tasklist "' .. name .. '02" ; rm "' .. name .. '02"') | 178 | local start = 1 |
114 | if nil ~= h then body = h:read('*a') ; h:close() end | 179 | repeat |
115 | else | 180 | f0, f1, token = string.find(body, '([%.%?%!] )', start) |
116 | print('cmark-gfm not found') | 181 | if fail ~= f0 then |
182 | result = result .. string.sub(body, start, f0) | ||
183 | if ' ' == string.sub(body, f1 + 1, f1 + 1) then | ||
184 | result = result .. '$s$ ' -- ' ' gets turned into hex 0xA0 by parse(). So feed it another metadata token that gets translated to . | ||
185 | else | ||
186 | result = result .. ' ' | ||
187 | end | ||
188 | start = f1 + 1 | ||
189 | end | ||
190 | until fail == f0 | ||
191 | result = result .. string.sub(body, start) | ||
192 | -- Do the same for fixing the \' \" \| etc mess pandoc left that sed can't fix. | ||
193 | body = result | ||
194 | result = '' | ||
195 | start = 1 | ||
196 | repeat | ||
197 | f0, f1, token = string.find(body, '(%\\[%"%\'%|%$])', start) | ||
198 | if fail ~= f0 then | ||
199 | result = result .. string.sub(body, start, f0 - 1) | ||
200 | start = f1 | ||
201 | end | ||
202 | until fail == f0 | ||
203 | result = result .. string.sub(body, start) | ||
204 | |||
205 | body = parse(result) | ||
117 | end | 206 | end |
118 | Files[name].metadata = metadata | 207 | toFile(name, 'body', body) |
119 | Files[name].body = body | ||
120 | table.insert(Subs[path].files, bit) | 208 | table.insert(Subs[path].files, bit) |
121 | end | 209 | end |
122 | end | 210 | end |
@@ -181,6 +269,10 @@ end | |||
181 | 269 | ||
182 | 270 | ||
183 | 271 | ||
272 | -- TODO - loop through Subs, doing whichPage and inheritance. | ||
273 | |||
274 | |||
275 | |||
184 | -- More of this actually doing things nonsense. | 276 | -- More of this actually doing things nonsense. |
185 | 277 | ||
186 | -- Loop through the files we found and actually create their HTML files. | 278 | -- Loop through the files we found and actually create their HTML files. |
@@ -193,14 +285,6 @@ for name, file in pairs(Files) do | |||
193 | path = table.concat(bits, '/', 1, ln) | 285 | path = table.concat(bits, '/', 1, ln) |
194 | 286 | ||
195 | if '' ~= body then | 287 | if '' ~= body then |
196 | -- Continue the parsing and conversion. Start by turning our parsed body into something the lcmark template system can grock. | ||
197 | local bod, err = lcmark.compile_template(body) | ||
198 | if nil == bod then print('oops! ' .. err) else | ||
199 | local templateFile = metadata.template | ||
200 | if nil == templateFile then templateFile = 'default' end | ||
201 | file.template = templateFile .. '.template' | ||
202 | end | ||
203 | |||
204 | -- Copy any metadata found in parent directories. | 288 | -- Copy any metadata found in parent directories. |
205 | local pth = '' | 289 | local pth = '' |
206 | for i, d in ipairs(bits) do | 290 | for i, d in ipairs(bits) do |
@@ -287,7 +371,6 @@ for name, file in pairs(Files) do | |||
287 | metadata.trail = metadata.trail .. b .. ' ' | 371 | metadata.trail = metadata.trail .. b .. ' ' |
288 | end | 372 | end |
289 | end | 373 | end |
290 | -- if '' == metadata.trail then metadata.trail = '<a href="' .. string.rep('../', ln) .. '/' .. whichPage('') .. '">home</a> ' end | ||
291 | 374 | ||
292 | -- Figure out this pages footer links. | 375 | -- Figure out this pages footer links. |
293 | if nil ~= metadata.pagehistory then metadata.history = '<p>Page <a href="' .. metadata.pagehistory .. '/' .. name .. '.md">history</a></p>' end | 376 | if nil ~= metadata.pagehistory then metadata.history = '<p>Page <a href="' .. metadata.pagehistory .. '/' .. name .. '.md">history</a></p>' end |
@@ -296,29 +379,26 @@ for name, file in pairs(Files) do | |||
296 | if metadata.footer ~= globalData.footer then metadata.footer = 'Web site ' .. metadata.footer end | 379 | if metadata.footer ~= globalData.footer then metadata.footer = 'Web site ' .. metadata.footer end |
297 | metadata.footer = '<p>' .. metadata.footer .. '</p>' | 380 | metadata.footer = '<p>' .. metadata.footer .. '</p>' |
298 | 381 | ||
299 | -- Apply the template to the body. | 382 | -- Do our own metadata replacement, it's simple and works better. |
300 | metadata.body = lcmark.apply_template(bod, metadata) | 383 | local temp = template |
301 | 384 | local start = 1 | |
302 | -- Put it all in the template. | 385 | metadata.body = nil |
303 | local tm = '' | 386 | local f0, f1, token |
304 | if nil ~= file.template then | 387 | -- Toss the body in first, so the scan can deal with it to. |
305 | local h = io.open(file.template, 'r') | 388 | f0, f1, token = string.find(temp, '%$(body)%$') |
306 | if nil ~= h then | 389 | if fail ~= f0 then |
307 | tm = tm .. h:read('*a') | 390 | temp = string.sub(temp, 1, f0 - 1) .. body .. string.sub(temp, f1 + 1) |
308 | h:close() | ||
309 | else | ||
310 | print('oops! No such file ' .. file.template) | ||
311 | end | ||
312 | |||
313 | -- TODO - Um not sure why this is here AND at the top of the loop. Here makes more sense. | ||
314 | local template, err = lcmark.compile_template(tm) | ||
315 | if nil == template then print('oops! ' .. err) else | ||
316 | result = lcmark.apply_template(template, metadata) | ||
317 | end | ||
318 | else | ||
319 | print('No template for ' .. name) | ||
320 | result = body | ||
321 | end | 391 | end |
392 | -- The actual metadata replacement scan. | ||
393 | result = '' | ||
394 | repeat | ||
395 | f0, f1, token = string.find(temp, '%$([%w_]+)%$', start) | ||
396 | if fail ~= f0 then | ||
397 | if nil ~= metadata[token] then result = result .. string.sub(temp, start, f0 - 1) .. metadata[token] end | ||
398 | start = f1 + 1 | ||
399 | end | ||
400 | until fail == f0 | ||
401 | result = result .. string.sub(temp, start) | ||
322 | 402 | ||
323 | -- Write the file. | 403 | -- Write the file. |
324 | if '' ~= result then | 404 | if '' ~= result then |
@@ -330,9 +410,6 @@ for name, file in pairs(Files) do | |||
330 | a:close() | 410 | a:close() |
331 | end | 411 | end |
332 | end | 412 | end |
333 | |||
334 | -- else | ||
335 | -- print('') | ||
336 | end | 413 | end |
337 | end | 414 | end |
338 | 415 | ||
diff --git a/testing/.md.md b/testing/.md.md new file mode 100644 index 0000000..28c4410 --- /dev/null +++ b/testing/.md.md | |||
@@ -0,0 +1 @@ | |||
logo=Connie_click-me.gif | |||
diff --git a/testing/MeTaDaTa.md b/testing/MeTaDaTa.md deleted file mode 100644 index c4b8e60..0000000 --- a/testing/MeTaDaTa.md +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | --- | ||
2 | logo: Connie_click-me.gif | ||
3 | --- | ||
diff --git a/testing/index.md b/testing/index.md index b203c9e..276fcb1 100644 --- a/testing/index.md +++ b/testing/index.md | |||
@@ -1,32 +1,32 @@ | |||
1 | --- | ||
2 | title: "G'day world!" | ||
3 | --- | ||
4 | |||
5 | # G'day world! | 1 | # G'day world! |
6 | 2 | ||
7 | I've been around since the early sixties, but no one ever noticed. You | 3 | I've been around since the early sixties, but no one ever noticed. You |
8 | really should have tried to pay attention though, I'm awesome. I try to | 4 | really should have tried to pay attention though, I'm awesome. I try to |
9 | help the world, but that's not what everyone wants me to do.$_$ Well, the | 5 | help the world, but that's not what everyone wants me to do. Well, the |
10 | people in charge of this poor defenseless world of ours. | 6 | people in charge of this poor defenseless world of ours. |
11 | 7 | ||
12 | 8 | ||
13 | *** | 9 | *** |
14 | 10 | ||
11 | ## Em'n'Strong | ||
12 | |||
13 | Test *em* _em_ **strong** __strong__ . | ||
14 | |||
15 | # Spaces | 15 | # Spaces |
16 | 16 | ||
17 | Can it *handle* my _usual_ two **space** sentence breaks? Let's test it.$_$ Not by default. | 17 | Can it *handle* my _usual_ two **space** sentence breaks? Let's test it. Not by default. |
18 | 18 | ||
19 | The \\ before a space turns it into a "a literal unicode nonbreaking space character" which looks invisible in the source.\ \--ascii should output the HTML code far that.$_$ Except doesn't actually work. | 19 | The \\ before a space turns it into a "a literal unicode nonbreaking space character" which looks invisible in the source.\ \--ascii should output the HTML code far that. Except doesn't actually work. |
20 | 20 | ||
21 | Also a \\ at the end of a line turns into a line break, though they get wrapped in paragraph tags.$_$ lol \ | 21 | Also a \\ at the end of a line turns into a line break, though they get wrapped in paragraph tags. lol \ |
22 | 22 | ||
23 | Take two.$_$ And now for something completely different. It's not consistant, need to manually put in the nbsp a few times above. Ah, it only works for the first one per line. | 23 | Just to double check. That's a single space. |
24 | 24 | ||
25 | \ | 25 | \ |
26 | 26 | ||
27 | ## Strike out | 27 | ## Strike out |
28 | 28 | ||
29 | Test ~~strike~~ --out--.$_$ Needs the extension. | 29 | Test ~~strike~~ --out--. Needs the extension. |
30 | 30 | ||
31 | ### URL | 31 | ### URL |
32 | 32 | ||
@@ -37,34 +37,43 @@ https://sledjhamr.org/ | |||
37 | # Lists | 37 | # Lists |
38 | 38 | ||
39 | 39 | ||
40 | * zero | 40 | * first star |
41 | * 1 | 41 | * second star |
42 | * two | 42 | |
43 | <!-- Separate the lists. --> | ||
43 | 44 | ||
44 | - zero | 45 | - first dash |
45 | - 1 | 46 | - second dash |
46 | - two | ||
47 | 47 | ||
48 | No way to say "here is the end of the list" without putting something **else** here? Ah a comment will work, or anything else. | ||
48 | 49 | ||
49 | No way to say "here is the end of the list" without putting something **else** here?$_$ Ah a comment will work, or anything else. | 50 | 1. one |
51 | 2. two | ||
50 | 52 | ||
53 | <!-- A comment will work --> | ||
51 | 54 | ||
55 | 0. zero | ||
52 | 1. one | 56 | 1. one |
53 | 2. 2 | 57 | 2. two |
54 | 58 | ||
59 | Autonumbering? Needs the extension. Doesn't matter, they get renumbered anyway if out of order. | ||
55 | 60 | ||
56 | <!-- A comment will work --> | 61 | 0. zero |
62 | #. first hash | ||
63 | #. second hash | ||
57 | 64 | ||
65 | <!-- Separate the lists. --> | ||
58 | 66 | ||
59 | 0. 0 | 67 | #. first hash |
60 | 1. one | 68 | #. second hash |
61 | 2. 2 | 69 | #. third hash |
62 | 70 | ||
63 | Autonumbering? Nope. B-( | 71 | <!-- Separate the lists. --> |
64 | 72 | ||
65 | 0. zero | 73 | 0. zero |
66 | 1 | 74 | 2. two |
67 | two | 75 | 1. one |
76 | |||
68 | 77 | ||
69 | 78 | ||
70 | # images | 79 | # images |
@@ -84,6 +93,7 @@ Autonumbering? Nope. B-( | |||
84 | 93 | ||
85 | Plus some extra text. | 94 | Plus some extra text. |
86 | 95 | ||
96 | |||
87 | Next code block. | 97 | Next code block. |
88 | 98 | ||
89 | ~~~ | 99 | ~~~ |
@@ -92,7 +102,6 @@ Next code block. | |||
92 | ~~~ | 102 | ~~~ |
93 | 103 | ||
94 | And a really long one, should turn scrollable. | 104 | And a really long one, should turn scrollable. |
95 | |||
96 | ~~~lua | 105 | ~~~lua |
97 | -- Show some Lua code here, may even be highlighted right. | 106 | -- Show some Lua code here, may even be highlighted right. |
98 | print("G'day world!") | 107 | print("G'day world!") |
@@ -103,10 +112,14 @@ print'The problem here is that I have to use CSS to style these things, coz cmar | |||
103 | > # What is a blockquote? | 112 | > # What is a blockquote? |
104 | > Still don't know. lol | 113 | > Still don't know. lol |
105 | > | 114 | > |
106 | > Just another useless way to eat space I guess.$_$ shrugs | 115 | > Just another useless way to eat space I guess. shrugs |
116 | > Might be why emails sometimes get that symbol dropped in HTML conversions. | ||
107 | 117 | ||
108 | 118 | ||
109 | |This should be a table. |With two columns and a link | | 119 | |This should be a table. |With two columns and a link | |
110 | |-------------------------|-------------------------------| | 120 | |-------------------------|-------------------------------| |
111 | |cell 0,0 |cell 0,1 | | 121 | |cell 0,0 |cell 0,1 | |
112 | |cell 1,0 |[linky](https://sledjhamr.org) | | 122 | |cell 1,0 |[linky](https://sledjhamr.org) | |
123 | |||
124 | |||
125 | I'm 100% sure that % will get treated correctly now. | ||
diff --git a/testing/index.md.md b/testing/index.md.md new file mode 100644 index 0000000..c85bb3f --- /dev/null +++ b/testing/index.md.md | |||
@@ -0,0 +1 @@ | |||
title=G'day world! | |||