當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript marked.setOptions函數代碼示例

本文整理匯總了TypeScript中marked.setOptions函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setOptions函數的具體用法?TypeScript setOptions怎麽用?TypeScript setOptions使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了setOptions函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: convertJson

function convertJson(input: string, outputFile: string, keysFile?: string, yamlFile?: string): Promise<void> {
	const render = new Renderer();

	marked.setOptions({
		renderer: render
	});

	marked(input);

	const promises: Array<Promise<void>> = [ writeFilePromise(outputFile, render.getOutput()) ];

	if (keysFile) {
		let treeKeys: any = {};

		addChildKeys(render.getFullObject().children, treeKeys);

		let jsonStr = JSON.stringify(treeKeys, null, 4);

		promises.push(writeFilePromise(keysFile, jsonStr));
	}

	if (yamlFile) {
		promises.push(writeFilePromise(yamlFile, render.getYamlOutput()));
	}

	return Promise.all(promises).then(() => undefined);
}
開發者ID:tristau,項目名稱:dnd-5e-srd,代碼行數:27,代碼來源:index.ts

示例2: ngOnInit

  ngOnInit() {
    let markdownFile = this.block.source;
    this.markdown = require('raw-loader!../../../../assets/articles/' + markdownFile);
    let md = marked.setOptions({
      highlight: (code) => Prism.highlight(code.trim(), Prism.languages.jsx)
    });

    this.markdown = md.parse(this.markdown.trim());
  }
開發者ID:AhmedFawzy,項目名稱:react-native-ui-kitten,代碼行數:9,代碼來源:react-markdown-block.component.ts

示例3: constructor

  constructor() {
    marked.setOptions({
      langPrefix: 'hljs ',
      highlight: function (code: string, lang: string) {
        return hljs.highlight(lang, code).value;
      }
    });

    fs.watchFile(entriesFilename, () => this.loadBlogEntries());
    this.loadBlogEntries(); 
  }
開發者ID:eliakaris,項目名稱:blog,代碼行數:11,代碼來源:BlogProvider.ts

示例4: transform

	transform(value: string, args: string[]) : any {
		marked.setOptions({
			renderer: new marked.Renderer(),
			gfm: true,
			tables: true,
			breaks: false,
			pedantic: false,
			sanitize: true,
			smartLists: true,
			smartypants: false
		});
		var result = marked(value);
				return result;
		}
開發者ID:Bitfroest,項目名稱:CopterLeague,代碼行數:14,代碼來源:markdown.pipe.ts

示例5: convertToMarkdown

export function convertToMarkdown(data) {
  marked.setOptions({
    renderer: new marked.Renderer(),
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: true,
    smartLists: true,
    smartypants: false
  });

  return marked(data);
}
開發者ID:343829084,項目名稱:growth2,代碼行數:14,代碼來源:helper.ts

示例6: constructor

    constructor(private sanitizer: DomSanitizationService) {
        this.md = marked;
        const renderer = new this.md.Renderer();
        renderer.code = (code, language) => {
            // Check whether the given language is valid for highlight.js.
            const validLang = !!(language && highlight.getLanguage(language));
            // Highlight only if the language is valid.
            const highlighted = validLang ? highlight.highlight(language, code).value : code;
            // Render the highlighted code with `hljs` class.
            return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
        };

        // Set the renderer to marked.
        marked.setOptions({ renderer });
    }
開發者ID:seattlecodercamps,項目名稱:Blixen,代碼行數:15,代碼來源:markdown.component.ts

示例7: renderMarkdownToHtml

function renderMarkdownToHtml(markdown: string) {
  marked.setOptions({
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    renderer: new marked.Renderer(),
    highlight: (code, lang) => {
      return highlightAuto(code, lang ? [lang] : undefined).value;
    }
  });

  return marked(markdown);
}
開發者ID:kevinphelps,項目名稱:kevinphelps.me,代碼行數:17,代碼來源:markdown.pipe.ts

示例8: formatMarkdownValue

export function formatMarkdownValue(value, format) {
  if (format === "html" || format === "markdown") {
    const renderer = new marked.Renderer()
    marked.setOptions({
      renderer,
      gfm: true,
      tables: true,
      breaks: true,
      pedantic: false,
      sanitize: false,
      smartypants: false,
    })
    return marked(value)
  }

  return value
}
開發者ID:xtina-starr,項目名稱:metaphysics,代碼行數:17,代碼來源:markdown.ts

示例9: initializeMarked

 /**
  * Support GitHub flavored Markdown, leave sanitizing to external library.
  */
 function initializeMarked(): void {
   if (markedInitialized) {
     return;
   }
   markedInitialized = true;
   marked.setOptions({
     gfm: true,
     sanitize: false,
     tables: true,
     // breaks: true; We can't use GFM breaks as it causes problems with tables
     langPrefix: `cm-s-${CodeMirrorEditor.defaultConfig.theme} language-`,
     highlight: (code, lang, callback) => {
       let cb = (err: Error | null, code: string) => {
         if (callback) {
           callback(err, code);
         }
         return code;
       };
       if (!lang) {
         // no language, no highlight
         return cb(null, code);
       }
       Mode.ensure(lang)
         .then(spec => {
           let el = document.createElement('div');
           if (!spec) {
             console.log(`No CodeMirror mode: ${lang}`);
             return cb(null, code);
           }
           try {
             Mode.run(code, spec.mime, el);
             return cb(null, el.innerHTML);
           } catch (err) {
             console.log(`Failed to highlight ${lang} code`, err);
             return cb(err, code);
           }
         })
         .catch(err => {
           console.log(`No CodeMirror mode: ${lang}`);
           console.log(`Require CodeMirror mode error: ${err}`);
           return cb(null, code);
         });
       return code;
     }
   });
 }
開發者ID:jupyter,項目名稱:jupyterlab,代碼行數:49,代碼來源:renderers.ts

示例10: formatPrInfo

    function formatPrInfo(pull, length) {
        const paddedLength = length - 5
        const title = wrap(paddedLength)(pull.title)

        const labels = pull.labels.length > 0 && pull.labels.map(label => label.name).join(', ')
        const singularOrPlural = labels && pull.labels.length > 1 ? 's' : ''
        const formattedLabels = labels
            ? logger.colors.yellow(`\nLabel${singularOrPlural}: ${labels}`)
            : ''

        let info = `${title}${formattedLabels}`

        if (showDetails) {
            marked.setOptions({
                renderer: new TerminalRenderer({
                    reflowText: true,
                    width: paddedLength,
                }),
            })

            info = `
                ${logger.colors.blue('Title:')}

                ${title}

                ${formattedLabels.split('\n')[1] || ''}

                ${logger.colors.blue('Body:')}

                ${marked(pull.body || 'N/A')}
            `
        }

        if (options.link || showDetails) {
            info = `
                ${info}
                ${logger.colors.cyan(pull.html_url)}
            `
        }

        return info
            .replace(/  +/gm, '')
            .replace(/(\n\n\n)/gm, '\n')
            .trim()
    }
開發者ID:node-gh,項目名稱:gh,代碼行數:45,代碼來源:pull-request.ts

示例11: convertMarkedHtml

export function convertMarkedHtml(content: string): string {
  marked.setOptions({
    highlight: function (code: string, lang: string): string {
      if (lang === undefined) {
          return code
      }
      
      const langSplit = lang.split(':')
      try {
          return highlight(langSplit[0], code).value
      } catch (e) {
          console.log(e.message)
          return code
      }
    }
  })

  return marked(content)
}
開發者ID:civic,項目名稱:markcat,代碼行數:19,代碼來源:marked.ts

示例12: catch

import marked from 'marked';
import hjs from 'highlightjs';

marked.setOptions({
  gfm:         true,
  tables:      true,
  breaks:      false,
  sanitize:    false,
  smartypants: false,
  pedantic:    false,
  highlight: (code, lang) => {
    let result: hjs.IHighlightResult|hjs.IAutoHighlightResult;
    // highlight.js throws an error when highlighting an unknown lang.
    if (lang) {
      try {
        result = hjs.highlight(lang, code);
      } catch (err) {
        result = hjs.highlightAuto(code);
      }
    } else {
      result = hjs.highlightAuto(code);
    }
    // Neuter interpolations. This is necessary to prevent atril from
    // evaluating them in code blocks.
    result.value = result.value.replace(/\{\{((?:[^}]|}(?=[^}]))*)\}\}/g, '{{<span>$1</span>}}');
    return result.value;
  }
});

/**
 * marked rendering enhancements.
開發者ID:Mitranim,項目名稱:atril,代碼行數:31,代碼來源:config.ts

示例13: setOptions

 public static setOptions(options: MarkedOptions): void {
     marked.setOptions(options);
 }
開發者ID:rajkeshwar,項目名稱:rajkeshwar-repo,代碼行數:3,代碼來源:common.pipes.ts

示例14: function

import { Directive, ElementRef, Input,HostListener  } from '@angular/core';
import marked from 'marked';
import highlight from 'highlight.js'


marked.setOptions({
  renderer: new marked.Renderer(),
  gfm: true,
  tables: true,
  breaks: false,
  pedantic: false,
  sanitize: false,
  smartLists: true,
  smartypants: false,
  highlight: function (code) {
    return highlight.highlightAuto(code).value;
  }
});

@Directive({
  selector: '[withMarkdown]'
})
export class MarkdownDirective {

  @Input('withMarkdown') content:string;

  constructor(
    private el: ElementRef
  ) {
    this.el.nativeElement.classList.add('article-viewer')
  }
開發者ID:ZhaoUjun,項目名稱:bolg-v1,代碼行數:31,代碼來源:markdown.directive.ts

示例15: highlightFn

const options = {
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: true,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    langPrefix: 'lang-',
    renderer: new marked.Renderer()
};

options.renderer.code = function highlightFn(code, language) {
    const validLang = !!(language && hljs.getLanguage(language));
    const highlighted = validLang ? hljs.highlight(language, code).value : code;
    return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};

marked.setOptions(options);

@Injectable()
export class MarkdownService {
    constructor(private _domSanitizer: DomSanitizer) {}
    render(input: string) {
        if (!input) return;
        return this._domSanitizer.bypassSecurityTrustHtml(marked(input));
    }
}

開發者ID:csgpro,項目名稱:csgpro.com,代碼行數:28,代碼來源:markdown.service.ts


注:本文中的marked.setOptions函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。