Skip to content

Commit

Permalink
Merge branch 'master' of github.com:obgnail/typora_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
obgnail committed Jan 24, 2025
2 parents 8d6bdfc + 92aef05 commit 1fffec1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugin/custom/plugins/callouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,33 @@ class calloutsPlugin extends BaseCustomPlugin {

afterExport = (html, ...args) => {
if (!this.check(args)) return;

const regex = new RegExp("<blockquote>", "g");
const count = (html.match(regex) || []).length;
const quotes = Array.from(this.utils.entities.querySelectorAllInWrite("blockquote"));
if (count !== quotes.length) return html;

let idx = -1;
return html.replace(regex, origin => {
html = html.replace(regex, origin => {
idx++;
let result = origin;

const quote = quotes[idx];
if (quote && quote.classList.length) {
const type = quote.getAttribute("callout-type");
result = `<blockquote class="${quote.className}" callout-type="${type}">`;
}
return result;
})
});

// 补上属性 data-type
const spanRegex = /(<span>)\[!(\w+)\](<\/span>)/g;
html = html.replace(spanRegex, (match, openTag, type, closeTag) => {
const typeValue = type.charAt(0).toUpperCase() + type.slice(1).toLowerCase();
return `<span data-type="${typeValue}">[!${type}]</span>`;
});

return html;
}
}

Expand Down

0 comments on commit 1fffec1

Please sign in to comment.