snow-editor

small markdown and org-mode editor
Log | Files | Refs | README

pipeline.js (936B)


      1 import { unified } from 'unified';
      2 import reorgParse from '@orgajs/reorg-parse';
      3 import reorgRehype from '@orgajs/reorg-rehype';
      4 import rehypeStringify from 'rehype-stringify';
      5 import { enhanceOrgHtml } from './enhanceHtml.js';
      6 import { normalizeOrgContent } from './normalize.js';
      7 import { sanitizeOrgHtml } from './sanitize.js';
      8 
      9 let processor = null;
     10 
     11 function getProcessor() {
     12   if (!processor) {
     13     processor = unified()
     14       .use(reorgParse)
     15       .use(reorgRehype)
     16       .use(rehypeStringify);
     17   }
     18   return processor;
     19 }
     20 
     21 function processOrg(content) {
     22   return getProcessor().processSync(normalizeOrgContent(content)).toString();
     23 }
     24 
     25 export function orgToHtmlSync(content) {
     26   if (!content || !content.trim()) return '';
     27   const raw = enhanceOrgHtml(processOrg(content));
     28   return sanitizeOrgHtml(raw);
     29 }
     30 
     31 export function orgToRawHtmlSync(content) {
     32   if (!content || !content.trim()) return '';
     33   return processOrg(content);
     34 }