diff --git a/docs/USING_ADVANCED.md b/docs/USING_ADVANCED.md index ba758e56f5..c38e230cc1 100644 --- a/docs/USING_ADVANCED.md +++ b/docs/USING_ADVANCED.md @@ -73,9 +73,9 @@ console.log(marked.parse(markdownString)); |smartypants (**removed**)|`boolean` |`false` |v0.2.9 |Removed in v8.0.0 use [`marked-smartypants`](https://www.npmjs.com/package/marked-smartypants) to use "smart" typographic punctuation for things like quotes and dashes.| |xhtml (**removed**)|`boolean` |`false` |v0.3.2 |Removed in v8.0.0 use [`marked-xhtml`](https://www.npmjs.com/package/marked-xhtml) to emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.| -
extensionstokenizerAndRendererExtensionsname** more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle single backticks with underscore emphasis', () => {
+ const marked = new Marked();
+ const input = '__text `__` more__';
+ const expected = 'text __ more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Double backticks', () => {
+ it('should handle double backticks with emphasis correctly', () => {
+ const marked = new Marked();
+ const input = '**text ``**`` more**';
+ const expected = 'text ** more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle double backticks with nested single backticks', () => {
+ const marked = new Marked();
+ const input = '**text ``code with ` backtick`` more**';
+ const expected = 'text code with ` backtick more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle double backticks with underscore emphasis', () => {
+ const marked = new Marked();
+ const input = '__text ``__`` more__';
+ const expected = 'text __ more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Triple backticks', () => {
+ it('should handle triple backticks with emphasis correctly', () => {
+ const marked = new Marked();
+ const input = '**text ```**``` more**';
+ const expected = 'text ** more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle triple backticks with nested backticks', () => {
+ const marked = new Marked();
+ const input = '**text ```code with `` double backticks``` more**';
+ const expected = 'text code with `` double backticks more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Quadruple backticks', () => {
+ it('should handle quadruple backticks with emphasis correctly', () => {
+ const marked = new Marked();
+ const input = '**text ````**```` more**';
+ const expected = 'text ** more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle quadruple backticks with nested triple backticks', () => {
+ const marked = new Marked();
+ const input = '**text ````code with ``` triple backticks```` more**';
+ const expected = 'text code with ``` triple backticks more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Mixed emphasis and code combinations', () => {
+ it('should handle multiple code spans in emphasis', () => {
+ const marked = new Marked();
+ const input = '**start `code1` middle ``code2`` end**';
+ const expected = 'start code1 middle code2 end';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle emphasis inside code spans (should not process)', () => {
+ const marked = new Marked();
+ const input = '`**not bold**`';
+ const expected = '**not bold**';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle complex nested scenarios', () => {
+ const marked = new Marked();
+ const input = '*italic `code **not bold**` more italic*';
+ const expected = 'italic code **not bold** more italic';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle links with code spans', () => {
+ const marked = new Marked();
+ const input = '[link with `code`](url)';
+ const expected = 'link with code';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Regression tests for normal emphasis and code', () => {
+ it('should still handle normal emphasis correctly', () => {
+ const marked = new Marked();
+ const input = '**bold text**';
+ const expected = 'bold text';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should still handle normal code correctly', () => {
+ const marked = new Marked();
+ const input = '`code`';
+ const expected = 'code';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle emphasis and code separately', () => {
+ const marked = new Marked();
+ const input = '**bold** and `code`';
+ const expected = 'bold and code';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle nested emphasis correctly', () => {
+ const marked = new Marked();
+ const input = '**bold _italic_ bold**';
+ const expected = 'bold italic bold';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+
+ describe('Edge cases', () => {
+ it('should handle unmatched backticks', () => {
+ const marked = new Marked();
+ const input = '**text ` unmatched**';
+ const expected = 'text ` unmatched';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle empty code spans', () => {
+ const marked = new Marked();
+ const input = '**text `` `` more**';
+ const expected = 'text more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle code spans at boundaries', () => {
+ const marked = new Marked();
+ const input = '``code`` **bold**';
+ const expected = 'code bold';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+
+ it('should handle code spans with HTML entities', () => {
+ const marked = new Marked();
+ const input = '**text `<tag>` more**';
+ const expected = 'text <tag> more';
+
+ const result = marked.parseInline(input);
+ assert.strictEqual(result, expected);
+ });
+ });
+});
\ No newline at end of file
diff --git a/test_new_property.js b/test_new_property.js
new file mode 100644
index 0000000000..a5780ea227
--- /dev/null
+++ b/test_new_property.js
@@ -0,0 +1,97 @@
+import { Marked } from './src/marked.ts';
+
+// Test the backtick precedence fix
+console.log('Testing backtick precedence fix:');
+
+const testCases = [
+ {
+ input: '**text `**` more**',
+ expected: 'text ** more',
+ description: 'Single backticks with emphasis - code takes precedence'
+ },
+ {
+ input: '**text ``**`` more**',
+ expected: 'text ** more',
+ description: 'Double backticks with emphasis - code takes precedence'
+ },
+ {
+ input: '**text ```**``` more**',
+ expected: 'text ** more',
+ description: 'Triple backticks with emphasis - code takes precedence'
+ },
+ {
+ input: '**text ````**```` more**',
+ expected: 'text ** more',
+ description: 'Quadruple backticks with emphasis - code takes precedence'
+ },
+ {
+ input: '__text ``__`` more__',
+ expected: 'text __ more',
+ description: 'Double backticks with underscore emphasis'
+ },
+ {
+ input: '`**not bold**`',
+ expected: '**not bold**',
+ description: 'Code spans should prevent emphasis processing'
+ },
+ {
+ input: '**start `code` end**',
+ expected: 'start code end',
+ description: 'Code within emphasis should work'
+ }
+];
+
+testCases.forEach(({ input, expected, description }) => {
+ try {
+ // Create a fresh instance for each test
+ const marked = new Marked();
+ const result = marked.parseInline(input);
+ const passed = result === expected;
+ console.log(`${passed ? '✓' : '✗'} ${description}`);
+ if (!passed) {
+ console.log(` Input: ${input}`);
+ console.log(` Expected: ${expected}`);
+ console.log(` Got: ${result}`);
+ }
+ } catch (e) {
+ console.log(`✗ ${description} - Error: ${e.message}`);
+ }
+});
+
+// Test that normal cases still work
+console.log('\nTesting regression cases:');
+
+const regressionCases = [
+ {
+ input: '**bold text**',
+ expected: 'bold text',
+ description: 'Normal emphasis should still work'
+ },
+ {
+ input: '`code`',
+ expected: 'code',
+ description: 'Normal code should still work'
+ },
+ {
+ input: '**bold** and `code`',
+ expected: 'bold and code',
+ description: 'Separate emphasis and code should work'
+ }
+];
+
+regressionCases.forEach(({ input, expected, description }) => {
+ try {
+ // Create a fresh instance for each test
+ const marked = new Marked();
+ const result = marked.parseInline(input);
+ const passed = result === expected;
+ console.log(`${passed ? '✓' : '✗'} ${description}`);
+ if (!passed) {
+ console.log(` Input: ${input}`);
+ console.log(` Expected: ${expected}`);
+ console.log(` Got: ${result}`);
+ }
+ } catch (e) {
+ console.log(`✗ ${description} - Error: ${e.message}`);
+ }
+});
\ No newline at end of file