Skip to content

Commit

Permalink
Added heading multi-level parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxy committed May 6, 2024
1 parent 0f71a4a commit 974fbc6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/textmarked.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ function TextMarked(textarea, settings = {}) {
for (let i = 0; i < lines.length; i++) {
let line = lines[i];

// Heading REGEX replacer.
const headingReplacer = (sigil, value) => {
const level = sigil.length;

return `<h${level}>${value}</h${level}>`;
};

// List-item REGEX replacer.
const listReplacer = (tagName, value) => {
value = `<li>${value}</li>`;
Expand All @@ -519,7 +526,7 @@ function TextMarked(textarea, settings = {}) {
line

// Heading
.replace(/^#\s(.*)$/g, '<h1>$1</h1>')
.replace(/^(#{1,5})\s(.*)$/g, (_, v1, v2) => headingReplacer(v1, v2))

// Bold
.replace(/\*\*(.*)\*\*/g, '<strong>$1</strong>')
Expand Down

0 comments on commit 974fbc6

Please sign in to comment.