Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 405201c

Browse files
committed
fix(plugins/plugin-client-common): markdown mark tags sometimes confused with tabbed
1 parent 80d0c04 commit 405201c

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed

packages/test/src/api/Markdown.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
export default class Markdown {
1818
public readonly tip = '.kui--markdown-tip'
19+
public readonly tabs = '.kui--markdown-tabs'
20+
public readonly tab = `${this.tabs} .kui--markdown-tab button`
1921

2022
public tipWithTitle(title: string) {
2123
return `${this.tip}[data-title="${title}"]`
@@ -24,4 +26,8 @@ export default class Markdown {
2426
public tipContent(baseSelector = this.tip) {
2527
return `${baseSelector} > div`
2628
}
29+
30+
public tabWithTitle(title: string) {
31+
return `${this.tab}[data-title="${title}"]`
32+
}
2733
}

plugins/plugin-client-common/src/components/Content/Markdown/remark-mark.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
const RE_MARK = /([^=])?==([^=]+)==([^=])/g
18-
1917
/**
2018
* Allows us to support pymdown's `==hello==` which they transform to
2119
* HTML5 <mark>hello</mark> which seems to generally be presented with
2220
* highlighter background.
2321
*/
2422
export default function plugin(markdownText: string) {
25-
return markdownText.replace(RE_MARK, '$1<mark>$2</mark>$3')
23+
const RE_MARK_BASE = '==([^=]+)==([^=])'
24+
const RE_MARK = new RegExp(`([^=])${RE_MARK_BASE}`, 'g')
25+
const RE_MARK_AT_TOP = new RegExp(`^${RE_MARK_BASE}`, 'g')
26+
27+
return markdownText.replace(RE_MARK_AT_TOP, '<mark>$1</mark>$2').replace(RE_MARK, '$1<mark>$2</mark>$3')
2628
}

plugins/plugin-client-common/src/test/core/markdown/mark.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,39 @@
1515
*/
1616

1717
import { basename, dirname, join } from 'path'
18-
import { Common, CLI } from '@kui-shell/test'
1918
import { encodeComponent } from '@kui-shell/core'
19+
import { Common, CLI, Selectors } from '@kui-shell/test'
2020

2121
const ROOT = join(dirname(require.resolve('@kui-shell/plugin-client-common/tests/data/marktag1.md')), '..')
2222

23-
const IN1 = {
23+
interface Input {
24+
input: string
25+
marks: string[]
26+
tabs?: string[]
27+
}
28+
29+
const IN1: Input = {
2430
input: join(ROOT, 'data/marktag1.md'),
2531
marks: ['Markymark']
2632
}
2733

28-
const IN2 = {
34+
const IN2: Input = {
2935
input: join(ROOT, 'data/marktag2.md'),
30-
marks: ['Morkymork', 'Markymark']
36+
marks: IN1.marks.concat(['Morkymork'])
37+
}
38+
39+
const IN3: Input = {
40+
input: join(ROOT, 'data/marktag3.md'),
41+
marks: IN2.marks,
42+
tabs: ['Tab1Title', 'Tab2Title']
3143
}
32-
;[IN1, IN2].forEach(markdown => {
44+
45+
const IN4: Input = {
46+
input: join(ROOT, 'data/marktag4.md'),
47+
marks: IN3.marks.concat(['Mirkymirk']), // no 'Merkymerk' is it in Tab2, not yet rendered
48+
tabs: IN3.tabs
49+
}
50+
;[IN1, IN2, IN3, IN4].forEach(markdown => {
3351
describe(`mark tags in markdown ${basename(markdown.input)} ${process.env.MOCHA_RUN_TARGET ||
3452
''}`, function(this: Common.ISuite) {
3553
before(Common.before(this))
@@ -52,6 +70,16 @@ const IN2 = {
5270
})
5371
})
5472
)
73+
74+
if (markdown.tabs) {
75+
await Promise.all(
76+
markdown.tabs.map(tabTitle =>
77+
this.app.client
78+
.$(Selectors.Markdown.tabWithTitle(tabTitle))
79+
.then(_ => _.waitForExist({ timeout: CLI.waitTimeout }))
80+
)
81+
)
82+
}
5583
} catch (err) {
5684
await Common.oops(this, true)(err)
5785
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
==Markymark==
2+
3+
That should render has a `<mark>...</mark>`. This file allows testing
4+
the case where the mark at the very start of the file. Do not change
5+
this.
6+
7+
==Morkymork==
8+
=== "Tab1Title"
9+
Tab1Contents
10+
=== "Tab2Title"
11+
Tab2Contents
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== "Tab1Title"
2+
Tab1Contents
3+
==Markymark==
4+
=== "Tab2Title"
5+
Tab2Contents
6+
==Merkymerk==
7+
==Mirkymirk==
8+
9+
That should render has a `<mark>...</mark>`. This file allows testing
10+
the case where we mix tabs and marks, with some marks nested in the
11+
tabs, and the tabs at the very top of the file. Do not change that
12+
last part, as it is an important part of the test.
13+
14+
==Morkymork==

0 commit comments

Comments
 (0)