Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add renderMarkdown to ICompiler #16

Merged
merged 3 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class Compiler implements ICompiler {
return { content, metadata, renderedContent };
}

public renderMarkdown = (markdown: string) => marked(markdown, this.markedOptions);

/**
* Converts the content string into an array of `ContentNode`s. If the
* `contents` option is `html`, the string nodes will also be rendered with
Expand All @@ -51,7 +53,7 @@ export class Compiler implements ICompiler {
private renderContents(content: string, reservedTagWords: string[]) {
const splitContents = this.parseTags(content, reservedTagWords);
return splitContents
.map((node) => typeof node === "string" ? marked(node, this.markedOptions) : node)
.map((node) => typeof node === "string" ? this.renderMarkdown(node) : node)
.filter((node) => node !== "");
}

Expand Down
27 changes: 18 additions & 9 deletions src/plugins/kss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ export interface IKssModifier {
export interface IKssExample {
/** Raw documentation string. */
documentation: string;
/** HTML markup for example, with `{{.modifier}}` templates. */
/**
* Raw HTML markup for example with `{{.modifier}}` templates,
* to be used to render the markup for each modifier.
*/
markup: string;
/**
* Syntax-highlighted version of the markup HTML, to be used
* for rendering the markup itself with pretty colors.
*/
markupHtml: string;
/** Array of modifiers supported by HTML markup. */
modifiers: IKssModifier[];
/** Unique reference for addressing this example. */
Expand All @@ -39,10 +47,10 @@ export class KssPlugin implements IPlugin<IKssPluginData> {
public constructor(private options: kss.IOptions) {
}

public compile(cssFiles: IFile[], { objectify }: ICompiler) {
public compile(cssFiles: IFile[], dm: ICompiler) {
const styleguide = this.parseFiles(cssFiles);
const sections = styleguide.sections().map(convertSection);
const css = objectify(sections, (s) => s.reference);
const sections = styleguide.sections().map((s) => convertSection(s, dm));
const css = dm.objectify(sections, (s) => s.reference);
return { css };
}

Expand All @@ -57,18 +65,19 @@ export class KssPlugin implements IPlugin<IKssPluginData> {
}
}

function convertSection(section: kss.ISection): IKssExample {
function convertSection(section: kss.ISection, dm: ICompiler): IKssExample {
return {
documentation: section.description(),
documentation: dm.renderMarkdown(section.description()),
markup: section.markup() || "",
modifiers: section.modifiers().map(convertModifier),
markupHtml: dm.renderMarkdown(`\`\`\`html\n${section.markup() || ""}\n\`\`\``),
modifiers: section.modifiers().map((mod) => convertModifier(mod, dm)),
reference: section.reference(),
};
}

function convertModifier(mod: kss.IModifier): IKssModifier {
function convertModifier(mod: kss.IModifier, dm: ICompiler): IKssModifier {
return {
documentation: mod.description(),
documentation: dm.renderMarkdown(mod.description()),
name: mod.name(),
};
}
5 changes: 5 additions & 0 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface ICompiler {
* is.
*/
renderBlock: (blockContent: string, reservedTagWords?: string[]) => IBlock;

/**
* Render a string of markdown to HTML, using the options from `Documentalist`.
*/
renderMarkdown: (markdown: string) => string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

export interface IPlugin<T> {
Expand Down