all repos — pandoc-mycomarkup @ 6b60f4baeb09465951ae9e81c38f71d882b163fb

init

FossilOrigin-Name: baea440a36428f16539c36d5d0853f6d55081d9b3049cd67c06ebaa314cea7a7
wing
Thu, 10 Aug 2023 18:03:07 +0000
commit

6b60f4baeb09465951ae9e81c38f71d882b163fb

parent

f46392b5e0e51345b7f89f7f15fe64a0653e0254

2 files changed, 145 insertions(+), 0 deletions(-)

jump to
A README.md

@@ -0,0 +1,18 @@

+# pandoc-myco + +This is a custom writer I wrote for [pandoc](https://pandoc.org) for the [mycomarkup](https://codeberg.org/bouncepaw/mycomarkup) language that was made for the [mycorrhiza](https://codeberg.org/bouncepaw/mycorrhiza) wiki. + +I wrote this for my own use and thought I'd share it so that comes with some caveats. + +1. This is really my first time doing anything with lua and I didn't dive very deep into it. +2. While pandoc can convert many formats from one to another, I only tested this with markdown. +3. It's a writer only, no reading functionality. +4. It does what I wanted and not much more. + +I didn't implement everything, most functions are there but tables are a big thing I couldn't be bothered figuring out. There's also two functions that are a little hacky. + +Take that as you want, feel free to do whatever you want with it. + +# Usage + +`pandoc -f markdown -t myco.lua input_file.md -o output_file.myco`
A myco.lua

@@ -0,0 +1,127 @@

+Writer = pandoc.scaffolding.Writer + +-- Blocks + +Writer.Block.BulletList = function (bl) + blist = "" + for index, value in ipairs(bl.content) do + blist = blist .. "* " .. Writer.Blocks(value) .. "\n" + end + + return blist +end + +Writer.Block.BlockQuote = function (bq) + -- there is definitely a better way + return "> " .. tostring(Writer.Blocks(bq.content)):gsub("\n", "\n> ") +end + +Writer.Block.CodeBlock = function (cb) + return "```\n" .. cb.text .. "\n```" +end + +Writer.Block.Figure = function (fig) + -- definitely hacky + return string.sub(tostring(Writer.Blocks(fig.content)), 1, -3) .. " { " .. Writer.Blocks(fig.caption.long) .. " }\n}" +end + +Writer.Block.Header = function (header) + return string.rep("=", header.level) .. " " .. Writer.Inlines(header.content) +end + +Writer.Block.HorizontalRule = function (hr) + return "----" +end + +Writer.Block.OrderedList = function (ol) + olist = "" + for index, value in ipairs(ol.content) do + olist = olist .. tostring(index) .. ". " .. Writer.Blocks(value) .. "\n" + end + + return olist +end + +Writer.Block.Para = function (para) + return Writer.Inlines(para.content) +end + +Writer.Block.Plain = function (plain) + return Writer.Inlines(plain.content) +end + +Writer.Block.Table = function (table) + -- todo + return "" +end + +-- Inline + +Writer.Inline.Code = function (code) + return "`" .. code.text .. "`" +end + +Writer.Inline.Emph = function (em) + return "//" .. Writer.Inlines(em.content) .. "//" +end + +Writer.Inline.Image = function (img) + return "img {\n" .. img.src .. "\n}" +end + +Writer.Inline.LineBreak = function (lb) + return "\n" +end + +Writer.Inline.Link = function (link) + -- Check if link has text + if tostring(Writer.Inlines(link.content)) == tostring(link.target) then + l = link.target + else + l = link.target .. " | " .. Writer.Inlines(link.content) + end + + return "[[ " .. l .. " ]]" +end + +Writer.Inline.Quoted = function (quoted) + if quoted.quotetype == "SingleQuote" then + q = "'" + else + q = "\"" + end + + return q .. Writer.Inlines(quoted.content) .. q +end + +Writer.Inline.SoftBreak = function (sb) + return "\n" +end + +Writer.Inline.Space = function (space) + return " " +end + +Writer.Inline.Str = function (str) + return str.text +end + +Writer.Inline.Strikeout = function (strike) + return "~~" .. Writer.Inlines(strike.content) .. "~~" +end + +Writer.Inline.Strong = function (strong) + return "**" .. Writer.Inlines(strong.content) .. "**" +end + +Writer.Inline.Subscript = function (sub) + return ",," .. Writer.Inlines(sub.content) .. ",," +end + +Writer.Inline.Superscript = function (sup) + return "^^" .. Writer.Inlines(sup.content) .. "^^" +end + +Writer.Inline.Underline = function (under) + return "__" .. Writer.Inlines(under.content) .. "__" +end