本文整理汇总了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);
}
示例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());
}
示例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();
}
示例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;
}
示例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);
}
示例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 });
}
示例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);
}
示例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
}
示例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;
}
});
}
示例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()
}
示例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)
}
示例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.
示例13: setOptions
public static setOptions(options: MarkedOptions): void {
marked.setOptions(options);
}
示例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')
}
示例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));
}
}