Skip to content

Commit

Permalink
Fix image caption conversion and add media_files and layout to post c…
Browse files Browse the repository at this point in the history
…reation
  • Loading branch information
liraymond04 committed Dec 12, 2024
1 parent fd2eb00 commit 304bb55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
28 changes: 16 additions & 12 deletions filters/docx-to-md.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ function is_image_followed_by_paragraph(image, para)
return image and image.content[1].t == 'Image' and para
end

function Blocks (blocks)
for i = #blocks-1, 1, -1 do
function Blocks(blocks)
for i = #blocks - 1, 1, -1 do
local first, second = blocks[i], blocks[i + 1]
if is_image_followed_by_paragraph(blocks[i], blocks[i + 1]) then
first.c:insert(pandoc.Str("\n"))
for _, v in ipairs(second.c) do
first.c:insert(v)
end

local div = pandoc.Div({
first,
second
}, {style = "text-align:center"})
}, { style = "text-align:center" })

blocks:remove(i)
blocks:remove(i)
Expand All @@ -32,7 +36,7 @@ function Blocks (blocks)
if m then
for name, body in pairs(m) do
local div = pandoc.Para({ pandoc.RawInline("markdown", name .. " " .. body) })
blocks:insert(i+1, div)
blocks:insert(i + 1, div)
end
end
end
Expand All @@ -41,13 +45,13 @@ function Blocks (blocks)
end

function removeRange(tbl, start, finish)
for i = finish, start, -1 do
table.remove(tbl, i)
end
for i = finish, start, -1 do
table.remove(tbl, i)
end
end

function trim1(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
return (s:gsub("^%s*(.-)%s*$", "%1"))
end

function manage(elem)
Expand All @@ -67,7 +71,7 @@ function manage(elem)
note_str = note_str .. e.text:gsub("\\e", "")
ret[note_name] = note_str

if note_begin-1 >= 1 and elem.c[note_begin-1].t == "Space" then
if note_begin - 1 >= 1 and elem.c[note_begin - 1].t == "Space" then
note_begin = note_begin - 1
end
removeRange(elem.c, note_begin, i)
Expand All @@ -89,8 +93,8 @@ function manage(elem)
e.text, _ = trim1(e.text):gsub(":", "")
elem.c[i] = pandoc.RawInline("markdown", e.text)
note_begin = i + 1
if elem.c[i+1].t == "Space" then
elem.c:remove(i+1)
if elem.c[i + 1].t == "Space" then
elem.c:remove(i + 1)
end
end
elseif found_note and e.t == "Space" then
Expand Down
2 changes: 0 additions & 2 deletions posts/side_stories/Stand by Me Pleiades Part 4/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ media_files: ['posts/side_stories/Stand by Me Pleiades Part 4/media/image1.png',

<img src="./media/image2.png"
style="margin:auto;height:auto;width:6.5in" />

Stand by me Pleiades Part 4

</div>
Expand Down Expand Up @@ -1350,7 +1349,6 @@ negotiating with me instead?\]

<img src="./media/image1.png"
style="margin:auto;height:auto;width:6.5in" />

Petra on the way back, from Tanpenshuu 8, illustrated by: 福きつね

</div>
Expand Down
2 changes: 2 additions & 0 deletions scripts/process_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def create_new_post(file, metadata):
"content": metadata["content"],
"repo_url": metadata["repo_url"],
"file_path": metadata["file_path"],
"media_files": metadata["media_files"],
"layout": metadata["layout"],
"updated_at": str(datetime.datetime.now())
}

Expand Down

0 comments on commit 304bb55

Please sign in to comment.