本文整理汇总了TypeScript中marked类的典型用法代码示例。如果您正苦于以下问题:TypeScript marked类的具体用法?TypeScript marked怎么用?TypeScript marked使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了marked类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transform
transform(markdown: string): string {
return marked(markdown || "", {
highlight: function (code: string, lang: string): string {
return hljs.highlightAuto(code).value;
}
});
}
示例2: parseRaw
const parseEntry = (
entryDir: string,
entryId: EntryId,
parseRaw: (entryDir: string, entryId: EntryId) => RawEntry,
options: { noIds: boolean; }
): Entry => {
const { meta, data } = parseRaw(entryDir, entryId);
if (typeof meta.minutes === 'undefined') {
throw new Error('minutes is not defined');
}
if (typeof meta.pubdate === 'undefined') {
throw new Error('pubdate is not defined');
}
if (typeof meta.title === 'undefined') {
throw new Error('title is not defined');
}
const minutes = meta.minutes as number;
const pubdate = meta.pubdate as string;
const tags = (typeof meta.tags === 'undefined' ? [] : meta.tags) as string[];
const title = meta.title as string;
const date = toISOString(inTimeZone(parseISOString(pubdate), '+09:00'))
.substring(0, '2006-01-02'.length);
const renderer = new marked.Renderer();
if (options.noIds) {
renderer.heading = (text, level) => `<h${level}>${text}</h${level}>\n`;
}
const html = marked(data, { renderer });
const entry = {
id: entryId, data, date, html, minutes, pubdate, tags, title
};
return entry;
};
示例3: createData
export async function createData(
projectPackage: any,
graphdocPackage: any,
plugins: PluginInterface[],
type?: TypeRef
): Promise<TemplateData> {
const name = type && type.name;
const [headers, navigations, documents]: [Headers, Navs, Docs] = await Promise.all([
Plugin.collectHeaders(plugins, name),
Plugin.collectNavigations(plugins, name),
Plugin.collectDocuments(plugins, name),
]);
const title = name ||
projectPackage.graphdoc.title ||
'Graphql schema documentation';
const description = type ?
marked(type.description || '') :
projectPackage.description;
return {
title,
type,
description,
headers: headers.join(''),
navigations,
documents,
projectPackage,
graphdocPackage,
slug: slugTemplate
};
}
示例4: renderViewerContent
function renderViewerContent(files, selectedFile) {
const bodyMarkdown = marked(commit.body, { gfm: true, breaks: true });
$viewer.append(Mustache.render(historyViewerTemplate, {
commit,
bodyMarkdown,
usePicture: avatarType === "PICTURE",
useIdenticon: avatarType === "IDENTICON",
useBwAvatar: avatarType === "AVATAR_BW",
useColoredAvatar: avatarType === "AVATAR_COLOR",
Strings,
enableAdvancedFeatures
}));
renderFiles(files);
if (selectedFile) {
const $fileEntry = $viewer.find(".commit-files li[x-file='" + selectedFile + "'] a").first();
if ($fileEntry.length) {
toggleDiff($fileEntry);
window.setTimeout(() => {
$viewer.find(".body").animate({ scrollTop: $fileEntry.position().top - 10 });
}, 80);
}
}
attachEvents();
}
示例5: packages
export default function packages(state = initialState["packages"], action) {
switch (action.type) {
case actionTypes.CLEAR_PACKAGES:
return state.set("current", Package()).
set("nextRange", 0).
set("visible", List()).
set("totalCount", 0).
setIn(["ui", "current", "loading"], true).
setIn(["ui", "current", "exists"], false).
setIn(["ui", "visible", "loading"], true).
setIn(["ui", "visible", "exists"], false);
case actionTypes.POPULATE_EXPLORE:
return state.setIn(["explore"], List(action.payload));
case actionTypes.SET_CURRENT_PACKAGE:
if (action.error) {
return state.set("current", Package()).
setIn(["ui", "current", "errorMessage"],
action.error.message).
setIn(["ui", "current", "loading"], false).
setIn(["ui", "current", "exists"], false);
} else {
let p = Object.assign({}, action.payload);
p.manifest = marked(p.manifest);
return state.set("current", Package(p)).
setIn(["ui", "current", "errorMessage"], undefined).
setIn(["ui", "current", "exists"], true).
setIn(["ui", "current", "loading"], false);
}
case actionTypes.SET_PACKAGES_NEXT_RANGE:
return state.set("nextRange", action.payload);
case actionTypes.SET_PACKAGES_SEARCH_QUERY:
return state.set("searchQuery", action.payload);
case actionTypes.SET_PACKAGES_TOTAL_COUNT:
return state.set("totalCount", action.payload);
case actionTypes.SET_VISIBLE_PACKAGES:
if (action.error) {
return state.set("visible", List()).
setIn(["ui", "visible", "errorMessage"],
action.error.message).
setIn(["ui", "visible", "exists"], false).
setIn(["ui", "visible", "loading"], false);
} else {
return state.set("visible",
state.get("visible").concat(List(action.payload))).
setIn(["ui", "visible", "errorMessage"], undefined).
setIn(["ui", "visible", "exists"], true).
setIn(["ui", "visible", "loading"], false);
}
default:
return state;
}
}
示例6: it
it('should handle escaping', () => {
const source = 'I\'ve used to use "Š" charachters';
const expected = marked(source, {
smartypants: true
}).trim();
const html = renderToStaticMarkup(source);
expect(html).toContain(expected);
});
示例7: markdown
function markdown(input: Buffer, options: MarkdownOptions, callback: TransformCallback) {
const input_string = input.toString('utf8');
marked(input_string, options, (error: Error, output_string: string) => {
if (error) return callback(error);
const output = new Buffer(output_string, 'utf8');
callback(null, output);
});
}