Skip to content

Commit

Permalink
試しに文字色とかを設定可能に
Browse files Browse the repository at this point in the history
  • Loading branch information
karasugawasu committed Jan 27, 2024
1 parent 5da0090 commit c987285
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/shared/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,57 @@ const spoilerConfig = {
},
};

const textcolorConfig = {
validate: (params: string) => {
return params.trim().match(/^color\s+(.*)$/);
},

render: (tokens: any, idx: any) => {
const m = tokens[idx].info.trim().match(/^color\s+(.*)$/);
if (tokens[idx].nesting === 1) {
const color = mdToHtmlInline(md.utils.escapeHtml(m[1])).__html;
return `<div class="text-${color}">`;
} else {
// closing tag
return "</div>";
}
},
};

const bgcolorConfig = {
validate: (params: string) => {
return params.trim().match(/^bg\s+(.*)$/);
},

render: (tokens: any, idx: any) => {
const m = tokens[idx].info.trim().match(/^bg\s+(.*)$/);
if (tokens[idx].nesting === 1) {
const color = mdToHtmlInline(md.utils.escapeHtml(m[1])).__html;
return `<div class="bg-${color}">`;
} else {
// closing tag
return "</div>";
}
},
};

const alertConfig = {
validate: (params: string) => {
return params.trim().match(/^alert\s+(.*)$/);
},

render: (tokens: any, idx: any) => {
const m = tokens[idx].info.trim().match(/^alert\s+(.*)$/);
if (tokens[idx].nesting === 1) {
const color = mdToHtmlInline(md.utils.escapeHtml(m[1])).__html;
return `<div class="alert alert-${color}" role="alert">`;
} else {
// closing tag
return "</div>\n";
}
},
};

const html5EmbedConfig = {
html5embed: {
useImageSyntax: true, // Enables video/audio embed with ![]() syntax (default)
Expand Down Expand Up @@ -223,6 +274,9 @@ export function setupMarkdown() {
.use(markdown_it_footnote)
.use(markdown_it_html5_embed, html5EmbedConfig)
.use(markdown_it_container, "spoiler", spoilerConfig)
.use(markdown_it_container, "color", textcolorConfig)
.use(markdown_it_container, "bgcolor", bgcolorConfig)
.use(markdown_it_container, "alert", alertConfig)
.use(markdown_it_highlightjs, { inline: true })
.use(markdown_it_ruby)
.use(localInstanceLinkParser)
Expand Down

0 comments on commit c987285

Please sign in to comment.