You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

import {isNamedSection, MarkMark} from './types'
export class HtmlRenderer {
public render(mm: MarkMark): string {
let mmLines: string[] = []
for ( const section of mm.sections ) {
mmLines.push('<section class="markmark section">')
// if this section has a title/description, write those out
if ( isNamedSection(section) ) {
mmLines.push(`<h1 class="markmark section-title">${section.title}</h1>`)
if ( section.description ) {
mmLines.push(`<p class="markmark section-description">${section.description}</p>`)
}
}
mmLines.push('<ul class="markmark section-list">')
for ( const link of section.links ) {
let linkTitle = `${link.title}`
if ( link.tags.length ) {
linkTitle += ` <span class="markmark link-tags">${link.tags.map(x => '<span class="markmark link-tag">#' + x + '</span>').join(' ')}</span>`
}
mmLines.push(`<li class="markmark link-title">${linkTitle}<ul class="markmark url-list">`)
for ( const url of link.urls ) {
mmLines.push(`<li class="markmark link-url"><a href="${url}" target="_blank">${url}</a></li>`)
}
mmLines.push('</ul></li>')
}
mmLines.push('</ul>')
mmLines.push('</section>')
}
return mmLines.join('\n')
}
}