Skip to content

Commit 126a241

Browse files
Merge pull request #8 from inavitski-sc/master
Added supporting of links in headers.
2 parents 349d530 + d618249 commit 126a241

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

GitHubToCBuilder.user.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name GitHubToCBuilder
33
// @namespace https://scand.com/
4-
// @version 0.1.4
4+
// @version 0.1.5
55
// @description ToC builder for GitHub markdown markup docs (.md and Wiki)
66
// @author vkuleshov-sc
77
// @author achernyakevich-sc
@@ -19,7 +19,9 @@
1919
}
2020

2121
const getHeaderText = headerLine => {
22-
return headerLine.replace(/#+\s+/, '');
22+
return headerLine.replace(/#+\s+/, '')
23+
// For link in header we keep text only (remove URL and brackets)
24+
.replace(/\[(.*?)\]\(.*?\)/g, '$1');
2325
}
2426

2527
const getHeaderAnchor = headerText => {
@@ -109,6 +111,11 @@
109111
output: 'header1 and some text',
110112
testingFunc: getHeaderText,
111113
},
114+
{
115+
input: '# Header with [GitHub](https://github.com/) and [Google](https://google.com/) links',
116+
output: 'Header with GitHub and Google links',
117+
testingFunc: getHeaderText,
118+
},
112119
{
113120
input: `# header1\r\n### header2 some text\n## header3\r\n`,
114121
output: ['# header1', '### header2 some text', '## header3'],

TEST.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- [ToC Example](#toc-example)
2+
- [Header level 2](#header-level-2)
3+
- [Header level 3](#header-level-3)
4+
- [Header with GitHub and Google links](#header-with-github-and-google-links)
5+
6+
# ToC Example
7+
8+
## Header level 2
9+
10+
Quisque ornare at augue et tincidunt. Quisque facilisis, nibh eget egestas molestie, nisi enim mattis nisi, sit amet pretium felis tortor eu eros. Duis vitae tellus molestie, sagittis tellus id, faucibus neque. Vestibulum iaculis convallis neque id viverra.
11+
12+
### Header level 3
13+
14+
Vestibulum ac dolor orci. Nullam varius porttitor convallis. Proin id suscipit magna, non suscipit velit. Integer mattis venenatis sem, at laoreet ipsum luctus eget. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae.
15+
16+
## Header with [GitHub](https://github.com/) and [Google](https://google.com/) links
17+
18+
There are cases when a header could contain links, e.g. to Jira-tickets.

0 commit comments

Comments
 (0)