Skip to content

Commit

Permalink
Render markdown line by line
Browse files Browse the repository at this point in the history
fixes #123
  • Loading branch information
cdupuis committed Aug 24, 2018
1 parent eafc687 commit 665513e
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/sdm/ui/ConsoleMessageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ export class ConsoleMessageClient implements MessageClient, SlackMessageClient {
* @param {string} markdown
*/
private writeToChannel(channels: string[] | string, markdown: string) {
const outputText = withinRenderableSize(markdown) ?
marked(` **${channels}** ${this.dateString()} ` + markdown, this.markedOptions) :
markdown;
return this.sender(chalk.gray("#") + outputText);
const outputText = ` ${marked(`**${channels}**`).trim()} ${this.dateString()} ${markdown.split("\n")
.map(t => marked(t, this.markedOptions).trim()).join("\n")}`;
return this.sender(chalk.gray("#") + outputText + "\n");
}

public dateString() {
Expand All @@ -160,15 +159,3 @@ export class ConsoleMessageClient implements MessageClient, SlackMessageClient {
}

}

/**
* Make a guess whether the `marked` program can render this in markdown in a reasonable amount of time.
* We have observed that it can take 60s to render a twelve-item list of sufficient interestingness.
* See: https://github.com/atomist/sdm-local/issues/123
*/
function withinRenderableSize(markdown: string): boolean {
if (!markdown) {
return true;
}
return (markdown.length < 1000) && (markdown.split("\n").length < 12);
}

0 comments on commit 665513e

Please sign in to comment.