virtual-star/lib/struct/fragment.js
2025-04-21 21:46:30 -04:00

34 lines
763 B
JavaScript

import Showdown from 'showdown';
export const fragmentFormats = {
V_HTML: ".vs.html",
V_MARKDOWN: ".vs.md",
};
export class Fragment {
format;
sourceContent;
constructor(format, sourceContent) {
this.format = format;
this.sourceContent = sourceContent;
}
toHtml() {
if(this.format === fragmentFormats.V_MARKDOWN) {
const converter = new Showdown.Converter();
const htmlContent = converter.makeHtml(this.sourceContent);
return new Fragment(
fragmentFormats.V_HTML,
htmlContent
);
} else {
return new Fragment(
this.format,
this.sourceContent
);
}
}
}