[F] Fix hideSection()

This commit is contained in:
Hykilpikonna
2021-12-25 00:14:53 -05:00
parent 72e437b911
commit 61bffff3be
2 changed files with 23 additions and 10 deletions
+20 -8
View File
@@ -1,3 +1,4 @@
/* eslint-disable prefer-const */
/** /**
* Regex used in markdown extension parsing * Regex used in markdown extension parsing
*/ */
@@ -12,9 +13,10 @@ const re = {
* @param raw Extended markdown * @param raw Extended markdown
* @return Parsed 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 let i = 0
/** /**
@@ -35,22 +37,32 @@ function parseExtensions(raw: string): string
// Find next same-level or higher-level header's index // Find next same-level or higher-level header's index
let j = i + 1 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 // Run all commands in markdown
while (i < lines.length) while (i < lines.length)
{ {
console.log(`Line ${i}`)
// Find commands // Find commands
const r = re.command.exec(lines[i]) const r = re.command.exec(lines[i])
if (!r) continue if (r)
const cmd = r[0].substring(5).trim() {
const cmd = r[0].substring(5).trim()
// Run cmd // Run cmd
eval(cmd) console.log(`Running command`, cmd)
eval(cmd)
}
i++; i++;
} }
return raw return lines.join('\n')
} }
+3 -2
View File
@@ -8,6 +8,7 @@
import {Options, Vue} from 'vue-class-component'; import {Options, Vue} from 'vue-class-component';
import {marked} from 'marked'; import {marked} from 'marked';
import emojiRegex from 'emoji-regex'; import emojiRegex from 'emoji-regex';
import {parseExtensions} from '@/scripts/extended_markdown'
@Options({components: {}}) @Options({components: {}})
export default class About extends Vue export default class About extends Vue
@@ -18,9 +19,9 @@ export default class About extends Vue
{ {
// TODO: Cloudflare CDN // TODO: Cloudflare CDN
fetch("https://raw.githubusercontent.com/hykilpikonna/hykilpikonna/main/README.md").then(it => it.text()) 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 `<span class="emoji">${emoji}</span>` return `<span class="emoji">${emoji}</span>`
}))) }))))
} }
} }
</script> </script>