Add initial MarkMark spec and integrate my own links.mark.md file
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
40
src/markmark/markmark.renderer.ts
Normal file
40
src/markmark/markmark.renderer.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {isNamedSection, MarkMark} from './types'
|
||||
|
||||
export class MarkMarkRenderer {
|
||||
public render(mm: MarkMark): string {
|
||||
let mmLines: string[] = ['\n']
|
||||
|
||||
// Write the frontmatter
|
||||
mmLines.push(`[//]: #(markmark-syntax: ${mm.frontmatter.syntax})`)
|
||||
if ( mm.frontmatter.authorName ) mmLines.push(`[//]: #(markmark-author-name: ${mm.frontmatter.authorName})`)
|
||||
if ( mm.frontmatter.authorEmail ) mmLines.push(`[//]: #(markmark-author-email: ${mm.frontmatter.authorEmail})`)
|
||||
if ( mm.frontmatter.authorHref ) mmLines.push(`[//]: #(markmark-author-href: ${mm.frontmatter.authorHref})`)
|
||||
|
||||
for ( const section of mm.sections ) {
|
||||
mmLines.push('\n')
|
||||
|
||||
// if this section has a title/description, write those out
|
||||
if ( isNamedSection(section) ) {
|
||||
mmLines.push(`# ${section.title}\n`)
|
||||
if ( section.description ) {
|
||||
mmLines.push(`${section.description}\n`)
|
||||
}
|
||||
}
|
||||
|
||||
for ( const link of section.links ) {
|
||||
let linkTitle = `- ${link.title}`
|
||||
if ( link.tags.length ) {
|
||||
linkTitle += ` ${link.tags.map(x => '#' + x).join(' ')}`
|
||||
}
|
||||
|
||||
mmLines.push(linkTitle)
|
||||
|
||||
for ( const url of link.urls ) {
|
||||
mmLines.push(` - ${url}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mmLines.join('\n')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user