ep_markdown 11.0.14 → 11.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/exportMarkdown.ts CHANGED
@@ -218,9 +218,27 @@ const getMarkdownFromAtext = (pad, atext) => {
218
218
  const url = urlData[1];
219
219
  const urlLength = url.length;
220
220
  processNextChars(startIndex - idx);
221
+ // Close any currently-open inline format tags (bold, italic, etc.)
222
+ // before writing the URL. If we don't, processing the URL's chars
223
+ // re-emits `**` / `*` markers *inside* the Markdown link token,
224
+ // producing broken output like `[url](**https://example.com**)`
225
+ // (regression for #156).
226
+ const reopen = [...openTags];
227
+ const tags2close = [...openTags];
228
+ orderdCloseTags(tags2close);
229
+ for (let i = 0; i < propVals.length; i++) { propVals[i] = false; }
221
230
  assem.append(`[${url}](`);
222
- processNextChars(urlLength);
231
+ // Emit the URL's chars as raw text — links in Markdown never
232
+ // contain inline formatting markers.
233
+ assem.append(taker.take(urlLength));
234
+ idx += urlLength;
223
235
  assem.append(')');
236
+ // Restore the formatting tags so any trailing same-line text picks
237
+ // them back up.
238
+ for (const i of reopen.slice().reverse()) {
239
+ emitOpenTag(i);
240
+ propVals[i] = true;
241
+ }
224
242
  });
225
243
  }
226
244
 
@@ -229,8 +247,15 @@ const getMarkdownFromAtext = (pad, atext) => {
229
247
  // replace &, _
230
248
  assem = assem.toString();
231
249
  assem = assem.replace(/&/g, '\\&');
232
- // this breaks Markdown math mode: $\sum_i^j$ becomes $\sum\_i^j$
233
- assem = assem.replace(/_/g, '\\_');
250
+ // Only escape underscores OUTSIDE code spans / code blocks. On a line
251
+ // with the `heading: 'code'` attribute (rendered with the 4-space
252
+ // block-code prefix) underscores should be preserved verbatim,
253
+ // otherwise `myVar_name` comes out as `myVar\_name` in the exported
254
+ // Markdown rendering (regression for #156). Math-mode ($...$) still
255
+ // has no special handling here — that is a separate concern.
256
+ if (heading !== headingtags[6]) {
257
+ assem = assem.replace(/_/g, '\\_');
258
+ }
234
259
 
235
260
  return assem;
236
261
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ep_markdown",
3
3
  "description": "Edit and Export as Markdown in Etherpad",
4
- "version": "11.0.14",
4
+ "version": "11.0.16",
5
5
  "author": {
6
6
  "name": "John McLear",
7
7
  "email": "john@mclear.co.uk",
@@ -0,0 +1,35 @@
1
+ import {expect, test} from '@playwright/test';
2
+ import {clearPadContent, getPadBody, goToNewPad, selectAllText, writeToPad}
3
+ from 'ep_etherpad-lite/tests/frontend-new/helper/padHelper';
4
+
5
+ test.beforeEach(async ({page}) => {
6
+ await goToNewPad(page);
7
+ });
8
+
9
+ test.describe('ep_markdown', () => {
10
+ test('Bold section renders the markdown class on body when "Show Markdown" is enabled',
11
+ async ({page}) => {
12
+ const padBody = await getPadBody(page);
13
+ await padBody.click();
14
+ await clearPadContent(page);
15
+ await writeToPad(page, 'bold');
16
+ await selectAllText(page);
17
+
18
+ // Apply bold via the toolbar button.
19
+ await page.locator('.buttonicon-bold').click();
20
+
21
+ // Toggle "Show Markdown" in pad settings.
22
+ // Settings popup must be open for #options-markdown to be clickable.
23
+ await page.locator('.buttonicon-settings').click();
24
+ await page.locator('#options-markdown').click({force: true});
25
+
26
+ // The pad body should gain the `markdown` class so its CSS swaps
27
+ // <b> for visible **bold** rendering.
28
+ await expect(padBody).toHaveClass(/markdown/);
29
+
30
+ // The original text content is unchanged (the rendering is purely
31
+ // CSS-driven; the underlying text remains "bold" without the
32
+ // surrounding asterisks in the document model).
33
+ await expect(padBody.locator('div').first()).toHaveText('bold');
34
+ });
35
+ });
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- describe('Set formatting attributes and ensure ep_markdown displays properly', function () {
4
- // create a new pad before each test run
5
- beforeEach(async function () {
6
- this.timeout(60000);
7
- await helper.aNewPad();
8
- });
9
-
10
- it('Bold section is shown as **foo** when clicking Show Markdown', async function () {
11
- this.timeout(60000);
12
- const chrome$ = helper.padChrome$;
13
- const inner$ = helper.padInner$;
14
-
15
- const $editorContents = inner$('div');
16
-
17
- // clear pad
18
- $editorContents.sendkeys('{selectall}');
19
- inner$('div').first().sendkeys('bold');
20
- inner$('div').first().sendkeys('{selectall}');
21
- chrome$('.buttonicon-bold').click();
22
- chrome$('#options-markdown').click();
23
-
24
- await helper.waitForPromise(() => (inner$('div').first()[0].textContent === 'bold'));
25
-
26
- const hasMarkdown = inner$('body').hasClass('markdown');
27
- // TODO: Use a psuedo selector to ensure the value displayed to user is **bold**
28
- expect(hasMarkdown).to.be(true);
29
- });
30
- });