Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

added support for functions and tables in markdown #34

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion luapress/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,25 @@ local function _process_content(s, item)
-- Set $=key's
s = s:gsub('%$=url', config.url)

-- Get $key=value's (and remove from string)
-- Fetch key data from the posts. There are 3 variations on the key syntax:
-- The first version is $key=L'code' for defining lua functions
-- The second is $key=L{fields} for defining lua tables
-- The last is $key=value
-- Nota bene:
-- All matches are removed from 's' afterwards
-- Variations one and two can span multiple lines
-- Quotes do NOT have to be escaped when defining functions
-- Now, starting with code...
for k, v in s:gmatch('%$([%w]+)=L\'(.-)\'\n') do
item[k] = assert(loadstring('return '.. v))()
end
s = s:gsub('%$[%w]+=L\'.-\'\n', '')
-- ...then fields...
for k, v in s:gmatch('%$([%w]+)=L(%b{})\n') do
item[k] = assert(loadstring('return {'.. v ..'}'))()
end
s = s:gsub('%$[%w]+=L%b{}\n', '')
--Last, values...
for k, v in s:gmatch('%$([%w]+)=(.-)\n') do
item[k] = v
end
Expand Down