diff --git a/src/scripts/extended_markdown.ts b/src/scripts/extended_markdown.ts index 6ce32e7..7915f50 100644 --- a/src/scripts/extended_markdown.ts +++ b/src/scripts/extended_markdown.ts @@ -1,3 +1,4 @@ +/* eslint-disable prefer-const */ /** * Regex used in markdown extension parsing */ @@ -12,9 +13,10 @@ const re = { * @param raw Extended markdown * @return Parsed markdown */ -function parseExtensions(raw: string): string +export function parseExtensions(raw: string): string { - const lines = raw.replace('\r\n', '\n').split('\n') + // @ts-ignore + let lines = raw.replace('\r\n', '\n').split('\n') let i = 0 /** @@ -35,22 +37,32 @@ function parseExtensions(raw: string): string // Find next same-level or higher-level header's index let j = i + 1 - while (!(lines[i].startsWith('#') && re.hashes.exec(lines[i])![0].length <= level)) j++ + for (; j < lines.length; j++) + { + const r = re.hashes.exec(lines[j]) + if (r && r[0].length <= level) break + } + lines.splice(i, j - i) } // Run all commands in markdown while (i < lines.length) { + console.log(`Line ${i}`) + // Find commands const r = re.command.exec(lines[i]) - if (!r) continue - const cmd = r[0].substring(5).trim() + if (r) + { + const cmd = r[0].substring(5).trim() - // Run cmd - eval(cmd) + // Run cmd + console.log(`Running command`, cmd) + eval(cmd) + } i++; } - return raw + return lines.join('\n') } diff --git a/src/views/About.vue b/src/views/About.vue index 3d24f1b..8500f7e 100644 --- a/src/views/About.vue +++ b/src/views/About.vue @@ -8,6 +8,7 @@ import {Options, Vue} from 'vue-class-component'; import {marked} from 'marked'; import emojiRegex from 'emoji-regex'; +import {parseExtensions} from '@/scripts/extended_markdown' @Options({components: {}}) export default class About extends Vue @@ -18,9 +19,9 @@ export default class About extends Vue { // TODO: Cloudflare CDN fetch("https://raw.githubusercontent.com/hykilpikonna/hykilpikonna/main/README.md").then(it => it.text()) - .then(it => this.html = marked(it.replace(emojiRegex(), (emoji) => { + .then(it => this.html = marked(parseExtensions(it.replace(emojiRegex(), (emoji) => { return `${emoji}` - }))) + })))) } }