-
Notifications
You must be signed in to change notification settings - Fork 27
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. */ | ||
|
@@ -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(convertSection, dm); | ||
const css = dm.objectify(sections, (s) => s.reference); | ||
return { css }; | ||
} | ||
|
||
|
@@ -57,18 +65,19 @@ export class KssPlugin implements IPlugin<IKssPluginData> { | |
} | ||
} | ||
|
||
function convertSection(section: kss.ISection): IKssExample { | ||
function convertSection(this: ICompiler, section: kss.ISection): IKssExample { | ||
return { | ||
documentation: section.description(), | ||
documentation: this.renderMarkdown(section.description()), | ||
markup: section.markup() || "", | ||
modifiers: section.modifiers().map(convertModifier), | ||
markupHtml: this.renderMarkdown(`\`\`\`html\n${section.markup() || ""}\n\`\`\``), | ||
modifiers: section.modifiers().map(convertModifier, this), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again =( |
||
reference: section.reference(), | ||
}; | ||
} | ||
|
||
function convertModifier(mod: kss.IModifier): IKssModifier { | ||
function convertModifier(this: ICompiler, mod: kss.IModifier): IKssModifier { | ||
return { | ||
documentation: mod.description(), | ||
documentation: this.renderMarkdown(mod.description()), | ||
name: mod.name(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
export interface IPlugin<T> { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using map's
this
context in this fashion is pretty hacky. I know it's more performant than using a lambda in the map above, but just one more arg and this doesn't work.I think i'd prefer to just use an explicit argument and a lambda in the map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's so damn clever 👩🔬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, and kudos. But simple and clear is better, IMO