diff --git a/src/github-issues.test.ts b/src/github-issues.test.ts new file mode 100644 index 0000000..72affda --- /dev/null +++ b/src/github-issues.test.ts @@ -0,0 +1,17 @@ +import { tsMarkdown } from './rendering'; + +describe('https://github.com/kgar/ts-markdown/issues/40', () => { + describe('given text which contains multiple underscores within a single word', () => { + const paragraphText = `Hello, t_word_with_underscores`; + + const entries = [ + { + p: paragraphText, + }, + ]; + + test('should be the same text that was originally provided', () => { + expect(tsMarkdown(entries)).toBe(paragraphText); + }); + }); +}); diff --git a/src/renderers/text.test.ts b/src/renderers/text.test.ts index a41e0fb..b696886 100644 --- a/src/renderers/text.test.ts +++ b/src/renderers/text.test.ts @@ -13,82 +13,6 @@ describe('given a text entry', () => { }); }); - /** - * Based on this recommendation: https://www.markdownguide.org/basic-syntax/#bold-best-practices - */ - describe('with mid-word bolding', () => { - const textEntry: TextEntry = { - text: ['He', { bold: 'll' }, 'o'], - }; - - test('renders a string with asterisks to denote mid-word bolding', () => { - expect(tsMarkdown([textEntry])).toBe('He**ll**o'); - }); - }); - - describe('with mid-word bolding and underscore indicator', () => { - const textEntry: TextEntry = { - text: ['He', { bold: 'll', indicator: '_' }, 'o'], - }; - - test('renders a string with asterisks to denote mid-word bolding, ignoring indicator setting per best practice', () => { - expect(tsMarkdown([textEntry])).toBe('He**ll**o'); - }); - }); - - /** - * Based on this recomendation: https://www.markdownguide.org/basic-syntax/#bold-best-practices - */ - describe('with mid-word italicizing', () => { - const data: MarkdownEntry[] = [ - { - text: ['He', { italic: 'll' }, 'o'], - }, - ]; - - test('renders a string with asterisks to denote mid-word italicizing', () => { - expect(tsMarkdown(data)).toBe('He*ll*o'); - }); - }); - - describe('with mid-word tailicizing and underscore indicator', () => { - const textEntry: TextEntry = { - text: ['He', { italic: 'll', indicator: '_' }, 'o'], - }; - - test('renders a string with asterisks to denote mid-word italicizing, ignoring indicator setting per best practice', () => { - expect(tsMarkdown([textEntry])).toBe('He*ll*o'); - }); - }); - - describe('with mid-word bold and italics and underscore indicator', () => { - const textEntry: TextEntry = { - text: [ - 'He', - { italic: { bold: 'll', indicator: '_' }, indicator: '_' }, - 'o', - ], - }; - - test('renders a string with asterisks to denote mid-word bold and italicizing, ignoring indicator setting per best practice', () => { - expect(tsMarkdown([textEntry])).toBe('He***ll***o'); - }); - }); - - describe('with mid-word bold and italics and mixed indicators', () => { - const textEntry: TextEntry = { - text: [ - 'mid', - { italic: { bold: 'word', indicator: '_' }, indicator: '*' }, - 'rich-text', - ], - }; - - test('renders a string with asterisks to denote mid-word bold and italicizing, ignoring indicator setting per best practice', () => { - expect(tsMarkdown([textEntry])).toBe('mid***word***rich-text'); - }); - }); - describe('with a superscript', () => { const textEntry: TextEntry = { text: ['H', { sup: '2' }, 'O'], diff --git a/src/rendering.ts b/src/rendering.ts index ac6db83..0b36082 100644 --- a/src/rendering.ts +++ b/src/rendering.ts @@ -36,34 +36,9 @@ export function tsMarkdown( ? options.onDocumentFootnoteAppended(data, document, options) : document; - // TODO: Formalize a post-render callback option - document = correctInvalidMidWordBoldAndItalics(document); - return document; } -/** - * Finds and corrects and mid-word bold/italics that use hyphens, changing the hyphens to asterisks, per best practice: https://www.markdownguide.org/basic-syntax/#bold-best-practices - * - * @param document the rendered document - * @returns document with mid-world bold and italics set to asterisks - */ -function correctInvalidMidWordBoldAndItalics(document: string): string { - return document - .replace( - /(?[^\_^\s])(?[\_]{3})(?[^\s^\_]+)(?[\_]{3})|(?[\_]{3})(?[^\s^\_]+)(?[\_]{3})(?[^\_^\s])/g, - '$***$$***$' - ) - .replace( - /(?[^\_^\s])(?[\_]{2})(?[^\s^\_]+)(?[\_]{2})|(?[\_]{2})(?[^\s^\_]+)(?[\_]{2})(?[^\_^\s])/g, - '$**$$**$' - ) - .replace( - /(?[^\_^\s])(?[\_]{1})(?[^\s^\_]+)(?[\_]{1})|(?[\_]{1})(?[^\s^\_]+)(?[\_]{1})(?[^\_^\s])/g, - '$*$$*$' - ); -} - /** * Reduces an array of markdown entries to a single string. *