[AHK v2] Markdown to PHPbb Converter

Post your working scripts, libraries and tools.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

[AHK v2] Markdown to PHPbb Converter

25 Nov 2018, 10:57

Markdown to PHPbb Converter
Markdown to PHPbb Converter, leveraging Pandoc.
Convert from within the app or use a predefined hotkey.

Features
  • Compile via app
    Spoiler
  • Compile clipboard contents via hotkey
    Spoiler
  • Rebind Hotkeys
    Spoiler
  • Always On Top
    Spoiler
  • Named / Unnamed Spoilers
    Spoiler
  • Copy to clipboard
  • Unsaved changes indicator
  • Resizable
Requires
  • AutoHotkey_L v2.0-a099-ca386dc (or newer)
  • pandoc.exe (in PATH or script dir)
  • pclip.exe (in PATH or script dir)
  • ahk.lua (in script dir)
Downloads
  • AutoHotkey_L v2.0
  • Pandoc v2.4
  • PClip, from UnxUtils
  • ahk.lua, modified from sample.lua - see next post or download zip
  • MarkdownConverter.ahk
    Spoiler
  • testfile.md
    Spoiler
  • [Optional] Zip, includes:
    • ahk.lua
    • testfile.md
    • MarkdownConverter.ahk
    • Compiled MarkdownConverter.exe for v2
    • pandoc.exe not included, download separately
    • pclip.exe not included, download separately
MarkdownConverter.zip
(493.17 KiB) Downloaded 73 times
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

ahk.lua

25 Nov 2018, 10:58

-- Usage: pandoc -t ahk.lua

-- Blocksep is used to separate block elements.
function Blocksep()
return "\n\n"
end

-- This function is called once for the whole document. Parameters:
-- body, title, date are strings; authors is an array of strings;
-- variables is a table. One could use some kind of templating
-- system here; this just gives you a simple standalone HTML file.
function Doc(body, title, authors, date, variables)
return body
end

-- The functions that follow render corresponding pandoc elements.
-- s is always a string, attr is always a table of attributes, and
-- items is always an array of strings (the items in a list).
-- Comments indicate the types of other variables.
function Str(s)
return s
end

function Space()
return " "
end

function LineBreak()
return "\n"
end

function Emph(s)
return "[i]" .. s .. "[/i]"
end

function Strong(s)
return "[b]" .. s .. "[/b]"
end

function Superscript(s)
return s
end

function Strikeout(s)
return '[strike]' .. s .. '[/strike]'
end

function Link(s, src, tit)
local ret = '[url'
if s then
ret = ret .. '=' .. src
else
s = src
end
ret = ret .. "]" .. s .. "[/url]"
return ret
end

function CaptionedImage(src, tit, caption, attr)
return "[img]" .. src .. "[/img]"
end

function Image(s, src, tit)
return "[img]" .. src .. "[/img]"
end

function Code(s, attr)
return "[c]" .. s .. "[/c]"
end

function Plain(s)
return s
end

function Para(s)
return s
end

-- lev is an integer, the header level.
function Header(lev, s, attr)
if lev == 1 then
return "[size=200][b]" .. s .. "[/b][/size][hr][/hr]"
elseif lev == 2 then
return "[size=150][b]" .. s .. "[/b][/size][hr][/hr]"
elseif lev == 3 then
return "[size=120][b]" .. s .. "[/b][/size]"
elseif lev == 4 then
return "[b]" .. s .. "[/b]"
elseif lev == 5 then
return "[size=85][b]" .. s .. "[/b][/size]"
else
return "[size=85]" .. s .. "[/size]"
end
end

function BlockQuote(s)
return "[quote]\n" .. s .. "\n[/quote]"
end

function HorizontalRule()
return "\n[hr][/hr]\n"
end

function CodeBlock(s, attr)
return "[code]\n" .. s .. "\n[/code]"
end

function BulletList(items)
local buffer = {}
for _, item in ipairs(items) do
table.insert(buffer, "[*]" .. item)
end
return "[list]\n" .. table.concat(buffer, "\n") .. "\n[/list]"
end

function OrderedList(items)
local buffer = {}
for _, item in ipairs(items) do
table.insert(buffer, "[*]" .. item)
end
return "[list=1]\n" .. table.concat(buffer, "\n") .. "\n[/list]"
end

-- Caption is a string, aligns is an array of strings,
-- widths is an array of floats, headers is an array of
-- strings, rows is an array of arrays of strings.
function Table(caption, aligns, widths, headers, rows)
local tmpstr = '| '
for i, h in pairs(headers) do
tmpstr = tmpstr .. h .. ' | '
end
return ''
end

function RawBlock(format, str)
if format ~= "html" then
return "[code]\n" .. str .. "\n[/code]\n"
end
end

function Span(s, attr)
return s
end

function Div(s, attr)
return s .. "\n"
end

function DoubleQuoted(s)
return '"' .. s .. '"'
end

function SingleQuoted(s)
return "'" .. s .. "'"
end

function SoftBreak()
return "\n"
end

-- The following code will produce runtime warnings when you haven't defined
-- all of the functions you need for the custom writer, so it's useful
-- to include when you're working on a writer.
local meta = {}
meta.__index =
function(_, key)
io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key))
return function() return "" end
end
setmetatable(_G, meta)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [AHK v2] Markdown to PHPbb Converter

26 Nov 2018, 09:25

Hello

Code: Select all

msgbox 'very nice'


This works very well.
Thanks
  • for
  • sharing
  • :wave:
Cheers

Spoiler
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [AHK v2] Markdown to PHPbb Converter

26 Nov 2018, 10:51

thanks for giving it a shot.
for simple things it should work well enough, though it might have some issues with tricky nesting and/or multiple spoiler usage/combining spoilers with other elements, since the spoilers are being handled by a regex separately instead of pandoc.
if for some reason, no output at all is being generated, it might have to do with pandoc encountering some missing constructs not yet handled by the custom template ahk.lua, but one wouldn't know since it runs it a suppressed shell. i probably should get around to fixing that.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 14 guests