Skip to content

Commit

Permalink
Fixed Rendering Issue on lines containing furigana syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-kraft committed May 12, 2021
1 parent f1f3591 commit 7176158
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const TAGS = 'p, h1, h2, h3, h4, h5, h6, ol, ul, table'

const convertFurigana = (element:Text): Node => {
const matches = Array.from(element.textContent.matchAll(REGEXP))
let lastNode = element
for (const match of matches) {
const furi = match[2].split('|').slice(1) // First Element will be empty
const kanji = furi.length === 1 ? [match[1]] : match[1].split('')
Expand All @@ -19,8 +20,8 @@ const convertFurigana = (element:Text): Node => {
rubyNode.appendText(k)
rubyNode.createEl('rt', { text: furi[i] })
})
const nodeToReplace = element.splitText(element.textContent.indexOf(match[0]))
element = nodeToReplace.splitText(match[0].length)
const nodeToReplace = lastNode.splitText(lastNode.textContent.indexOf(match[0]))
lastNode = nodeToReplace.splitText(match[0].length)
nodeToReplace.replaceWith(rubyNode)
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-markdown-furigana",
"name": "Markdown Furigana",
"version": "1.1.1",
"version": "1.1.2",
"minAppVersion": "0.9.12",
"description": "Simple Markdown to Furigana Rendering Plugin for Obsidian.",
"author": "Steven Kraft",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-markdown-furigana",
"version": "1.1.1",
"version": "1.1.2",
"description": "Simple Markdown to Furigana Rendering Plugin for Obsidian.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 7176158

Please sign in to comment.