imdone-core 1.54.9 → 2.0.0

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.
Files changed (71) hide show
  1. package/README.md +2 -2
  2. package/lib/cli.js +114 -0
  3. package/lib/index.js +23 -0
  4. package/package.json +48 -66
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -37
  6. package/.github/workflows/ci.yml +0 -24
  7. package/.imdoneignore +0 -12
  8. package/.mocharc.json +0 -10
  9. package/.prettierrc +0 -6
  10. package/CHANGELOG.md +0 -160
  11. package/_navbar.md +0 -1
  12. package/cli.js +0 -74
  13. package/index-markdown.js +0 -55
  14. package/index.html +0 -184
  15. package/index.js +0 -1
  16. package/lib/ProjectContext.js +0 -42
  17. package/lib/adapters/date-time.js +0 -20
  18. package/lib/adapters/file-gateway.js +0 -127
  19. package/lib/adapters/git-download.js +0 -35
  20. package/lib/adapters/markdown.js +0 -168
  21. package/lib/adapters/parsers/DateLanguageParser.js +0 -10
  22. package/lib/adapters/parsers/content-transformer.js +0 -111
  23. package/lib/adapters/parsers/file/LocalFileParserFactory.js +0 -37
  24. package/lib/adapters/parsers/file/ReadStreamCodeParser.js +0 -126
  25. package/lib/adapters/parsers/file/ReadStreamMarkdownParser.js +0 -17
  26. package/lib/adapters/parsers/file/ReadStreamTaskParser.js +0 -104
  27. package/lib/adapters/parsers/function-parser.js +0 -29
  28. package/lib/adapters/parsers/task/CardContentParser.js +0 -376
  29. package/lib/adapters/parsers/task/CheckStyleTaskParser.js +0 -28
  30. package/lib/adapters/parsers/task/CodeStyleTaskParser.js +0 -24
  31. package/lib/adapters/parsers/task/HashStyleTaskParser.js +0 -27
  32. package/lib/adapters/parsers/task/MarkdownStyleTaskParser.js +0 -24
  33. package/lib/adapters/parsers/task/TaskParser.js +0 -38
  34. package/lib/adapters/readers/FileSystemProjectReader.js +0 -45
  35. package/lib/adapters/storage/config.js +0 -49
  36. package/lib/adapters/storage/tags.js +0 -30
  37. package/lib/adapters/yaml.js +0 -6
  38. package/lib/card.js +0 -300
  39. package/lib/config.js +0 -214
  40. package/lib/constants.js +0 -97
  41. package/lib/context/ApplicationContext.js +0 -32
  42. package/lib/context/StreamingApplicationContext.js +0 -31
  43. package/lib/controlers/SaveViewController.js +0 -10
  44. package/lib/default-settings.js +0 -37
  45. package/lib/domain/entities/FileProjectContext.js +0 -10
  46. package/lib/domain/entities/View.js +0 -30
  47. package/lib/domain/usecases/GetViewsUsecase.js +0 -50
  48. package/lib/domain/usecases/OpenProjectUsecase.js +0 -13
  49. package/lib/domain/usecases/SaveViewUsecase.js +0 -57
  50. package/lib/file.js +0 -1395
  51. package/lib/languages.js +0 -114
  52. package/lib/list.js +0 -105
  53. package/lib/migrate-config.js +0 -165
  54. package/lib/mixins/repo-fs-store.js +0 -424
  55. package/lib/mixins/repo-watched-fs-store.js +0 -195
  56. package/lib/plugins/archive-plugin.js +0 -70
  57. package/lib/plugins/default-board-actions-plugin.js +0 -56
  58. package/lib/plugins/default-board-properties-plugin.js +0 -101
  59. package/lib/plugins/epic-plugin.js +0 -176
  60. package/lib/plugins/extension-plugin.js +0 -87
  61. package/lib/plugins/persist-tags-plugin.js +0 -13
  62. package/lib/plugins/plugin-manager.js +0 -421
  63. package/lib/plugins/plugin-registry.js +0 -61
  64. package/lib/project-factory.js +0 -45
  65. package/lib/project.js +0 -911
  66. package/lib/repository.js +0 -1746
  67. package/lib/task.js +0 -798
  68. package/lib/tools.js +0 -250
  69. package/lib/usecases/get-imdone-url.js +0 -6
  70. package/lib/usecases/get-project-tags.js +0 -16
  71. package/lib/usecases/get-tasks-in-file.js +0 -29
package/index-markdown.js DELETED
@@ -1,55 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const sidebar = '_index.md';
4
-
5
- function getMarkdownFiles(files = []) {
6
- return files.filter(file => file.endsWith('.md') && file !== sidebar && file !== '_navbar.md');
7
- }
8
-
9
- function getFileLinks(files) {
10
- return files.map(file => `- [${file.replace('.md', '')}](${file})`).join('\n');
11
- }
12
-
13
- function getSubDirLinks(files, directory) {
14
- const subDirs = files.filter(file => fs.statSync(path.join(directory, file)).isDirectory());
15
- const subDirsContainingMarkdown = subDirs.filter(subDir => fs.readdirSync(path.join(directory, subDir)).find(file => file.endsWith('.md'))
16
- );
17
- return subDirsContainingMarkdown.map(subDir => {
18
- const resource = fs.readdirSync(path.join(directory, subDir)).find(file => file.toLowerCase() === 'readme.md')
19
- ? 'README'
20
- : sidebar
21
- return `- [:file_folder: **${subDir}**](${subDir}/${resource})`;
22
- }).join('\n');
23
- }
24
-
25
- function getBreadCrumb(parentDir) {
26
- const homeLink = '[:house: **Home**](/README)';
27
- return parentDir ? `- ${homeLink}\n- [:arrow_heading_up: **Parent Directory**](${parentDir}${sidebar})` : '';
28
- }
29
-
30
- function createIndexes(directory, parentDir, title) {
31
- const basename = path.basename(directory);
32
- if (basename.startsWith('.')) {
33
- return;
34
- }
35
-
36
- title = title || basename;
37
-
38
- const files = fs.readdirSync(directory);
39
- const markdownFiles = getMarkdownFiles(files);
40
-
41
- if (markdownFiles.length > 0) {
42
- const subDirLinks = getSubDirLinks(files, directory);
43
- const fileLinks = getFileLinks(markdownFiles);
44
- const breadcrumb = getBreadCrumb(parentDir);
45
-
46
- fs.writeFileSync(path.join(directory, sidebar), `# ${title}\n${breadcrumb}\n${subDirLinks}\n${fileLinks}\n`);
47
- }
48
-
49
- files
50
- .filter(file => fs.statSync(path.join(directory, file)).isDirectory())
51
- .forEach(subDir => createIndexes(path.join(directory, subDir), parentDir ? path.join(parentDir, basename) + '/' : '/'));
52
- }
53
-
54
- createIndexes(process.cwd(), undefined, 'imdone-core');
55
- console.log('Indexes created successfully!');
package/index.html DELETED
@@ -1,184 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <title>imdone-core</title>
7
- <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
8
- <meta http-equiv="Pragma" content="no-cache">
9
- <meta http-equiv="Expires" content="0">
10
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
11
- <meta name="description" content="imdone-core">
12
- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
13
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" , rel="stylesheet">
14
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
15
- <link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/prism-themes@1.3.0/themes/prism-atom-dark.css'>
16
- <style>
17
- .sidebar-nav {
18
- margin-left: .5rem;
19
- }
20
-
21
- .sidebar-nav h2 {
22
- margin-left: 0.5rem;
23
- }
24
-
25
- .markdown-section pre>code {
26
- -webkit-font-smoothing: antialiased;
27
- background-color: inherit;
28
- color: inherit;
29
- padding: 1.5em .25em;
30
- }
31
-
32
- pre[class*="language-"] {
33
- padding: 0 .5em;
34
- margin: 0;
35
- overflow: auto;
36
- border-radius: 0.3em;
37
- }
38
-
39
- .markdown-section {
40
- font-size: 21px;
41
- margin: 0 8%;
42
- max-width: 100%;
43
- padding: 30px 15px 40px;
44
- position: relative;
45
- }
46
-
47
- a.button {
48
- -webkit-tap-highlight-color: transparent;
49
- text-align: center;
50
- box-sizing: border-box;
51
- text-decoration: none;
52
- line-height: 1.33333;
53
- border-radius: 3px;
54
- font-size: 1.5em;
55
- color: #fff;
56
- background-color: #286090;
57
- border-color: #204d74;
58
- background-image: none;
59
- font-weight: bold;
60
- padding: .25em .5em;
61
- margin: 0;
62
- height: 2em;
63
- }
64
- </style>
65
- </head>
66
-
67
- <body>
68
- <div id="app"></div>
69
- <!-- VueJs -->
70
- <!-- Production -->
71
- <!--<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>-->
72
- <!-- Development -->
73
- <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
74
- <script src="https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
75
- <script src="https://cdn.jsdelivr.net/npm/jsonpath@1.1.1/jsonpath.min.js"></script>
76
- <script>
77
- window.$docsify = {
78
- maxAge: 3600000,
79
- repo: 'https://github.com/imdone/imdone-core',
80
- loadSidebar: "_index.md",
81
- subMaxLevel: 5,
82
- loadNavbar: true,
83
- relativePath: true,
84
- search: {
85
- paths: 'auto',
86
- namespace: 'imdone-core'
87
- },
88
- customPageTitle: {
89
- prefix: 'imdone-core'
90
- },
91
- mermaidConfig: {
92
- querySelector: ".mermaid"
93
- },
94
- vueComponents: {
95
- 'load-yaml': {
96
- template: `
97
- <div>
98
- <strong><a :href="url">{{src}}</a></strong>
99
- </div>
100
- <pre>
101
- <code class="language-yaml">
102
- {{yaml}}
103
- </code>
104
- </pre>
105
- `,
106
- props: ['src', 'path'],
107
- data() {
108
- return {
109
- yaml: '',
110
- data: {},
111
- url: `${$docsify.repo}/${this.src}`
112
- };
113
- },
114
- created() {
115
- fetch(this.src)
116
- .then(async response => {
117
- const yaml = await response.text()
118
- const data = jsyaml.load(yaml)
119
- this.data = this.path ? jsonpath.query(data, this.path) : data
120
- this.yaml = '\n' + jsyaml.dump(this.data, { forceQuotes: true })
121
- })
122
- .catch(err => console.log(err));
123
- }
124
- },
125
- 'load-code': {
126
- template: `
127
- <div>
128
- <strong><a :href="url">{{src}}</a></strong>
129
- </div>
130
- <pre :data-lang="innerLang" :class="language">
131
- <code :class="language">{{text}}</code>
132
- </pre>
133
- `,
134
- props: ['src', 'path', 'lang'],
135
- data() {
136
- return {
137
- text: '',
138
- data: {},
139
- url: `${$docsify.repo}/${this.src}`
140
- };
141
- },
142
- created() {
143
- fetch(this.src)
144
- .then(async response => {
145
- this.text = '\n' + await response.text()
146
- })
147
- .catch(err => console.log(err));
148
- },
149
- computed: {
150
- language() {
151
- return `language-${this.innerLang}`
152
- },
153
- innerLang() {
154
- return this.lang || 'text'
155
- }
156
- }
157
- },
158
-
159
- },
160
- }
161
- </script>
162
- <script src="https://cdn.jsdelivr.net/npm/docsify@4"></script>
163
- <script src="https://cdn.jsdelivr.net/gh/rizdaprasetya/docsify-fix-pageload-scroll@master/index.js"></script>
164
- <script src="https://unpkg.com/docsify/lib/plugins/search.min.js"></script>
165
- <script src="https://unpkg.com/docsify/lib/plugins/zoom-image.min.js"></script>
166
- <script src="https://cdn.jsdelivr.net/npm/docsify-prism@latest/dist/docsify-prism.min.js"></script>
167
- <script src="https://unpkg.com/prismjs/components/prism-markdown.min.js"></script>
168
- <script src="https://unpkg.com/prismjs/components/prism-javascript.min.js"></script>
169
- <script src="https://unpkg.com/prismjs/components/prism-java.min.js"></script>
170
- <script src="https://unpkg.com/prismjs/components/prism-yaml.min.js"></script>
171
- <script src="https://unpkg.com/docsify-copy-code"></script>
172
- <script src="https://unpkg.com/docsify-sidebar-collapse/dist/docsify-sidebar-collapse.min.js"></script>
173
- <script src="https://unpkg.com/docsify-include-template/dist/docsify-include-template.js"></script>
174
- <script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/emoji.min.js"></script>
175
- <script src="https://cdn.jsdelivr.net/npm/@sujaykumarh/docsify-plugin-title@1.x/dist/plugin.min.js"></script>
176
- <script type="module">
177
- import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";
178
- mermaid.initialize({ startOnLoad: true });
179
- window.mermaid = mermaid;
180
- </script>
181
- <script src="https://unpkg.com/docsify-mermaid@2.0.1/dist/docsify-mermaid.js"></script>
182
- </body>
183
-
184
- </html>
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./lib');
@@ -1,42 +0,0 @@
1
- const FileProjectContext = require('./domain/entities/FileProjectContext')
2
- const { isNumber } = require('./adapters/parsers/task/CardContentParser')
3
-
4
- module.exports = class ProjectContext extends FileProjectContext {
5
- constructor(repo) {
6
- super()
7
- this.repo = repo
8
- }
9
-
10
- getOrder(list, order) {
11
- const config = this.repo.config
12
- if (config && config.keepEmptyPriority && order === undefined) return
13
- const tasks =
14
- list && this.repo.listExists(list) ? this.repo.getTasksInList(list) : []
15
- return getOrder(config, order, tasks)
16
- }
17
-
18
- get config() {
19
- return this.repo.config
20
- }
21
-
22
- toJSON() {
23
- return null
24
- }
25
- }
26
-
27
- const getOrder = function (config, order, tasks) {
28
- if (!config) return 0
29
- if (isNumber(order)) return Number(order)
30
- if (config.keepEmptyPriority) return ''
31
- if (tasks) {
32
- if (tasks.length == 0) {
33
- return 0
34
- } else if (config.isAddNewCardsToTop()) {
35
- return (isNumber(tasks[0].order) ? tasks[0].order : 0) - 10
36
- } else {
37
- const lastTask = tasks[tasks.length - 1]
38
- return (lastTask && isNumber(lastTask.order) ? lastTask.order : 0) + 10
39
- }
40
- }
41
- return 0
42
- }
@@ -1,20 +0,0 @@
1
- const moment = require('moment');
2
- let innerNoDST = false;
3
-
4
- function setNoDST(noDST) {
5
- innerNoDST = noDST;
6
- }
7
-
8
- function getIsoDateWithOffset (date) {
9
- const momentDate = moment(date);
10
- if (momentDate.isDST() && innerNoDST) {
11
- const offset = momentDate.utcOffset();
12
- momentDate.utcOffset(offset - 60);
13
- }
14
- return momentDate.format();
15
- }
16
-
17
- module.exports = {
18
- setNoDST,
19
- getIsoDateWithOffset
20
- }
@@ -1,127 +0,0 @@
1
- const tools = require('../tools')
2
- const _path = require('path')
3
- let fs = require('fs')
4
- const sanitize = require('sanitize-filename')
5
-
6
- async function exists(path) {
7
- try {
8
- await fs.promises.access(path)
9
- return path
10
- } catch {
11
- return false
12
- }
13
- }
14
-
15
- function mkdirpSync(path) {
16
- console.warn('sync call')
17
- return require('mkdirp').sync(path, { fs })
18
- }
19
-
20
- function statSync(path) {
21
- console.warn('sync call')
22
- try {
23
- return fs.statSync(path)
24
- } catch {
25
- }
26
- }
27
-
28
- const gateway = {
29
- init(fileSystem = fs) {
30
- fs = fileSystem
31
- },
32
-
33
- sep: _path.sep,
34
-
35
- existsSync(...args) {
36
- console.warn('sync call')
37
- return fs.existsSync.apply({}, args)
38
- },
39
-
40
- exists,
41
-
42
- async stat(path, opts) {
43
- try {
44
- return await fs.promises.stat(path, opts)
45
- }
46
- catch {
47
- return false
48
- }
49
- },
50
-
51
- readFileSync(...args) {
52
- console.warn('sync call')
53
- return fs.readFileSync.apply({}, args)
54
- },
55
-
56
- appendFileSync(...args) {
57
- console.warn('sync call')
58
- return fs.appendFileSync.apply({}, args)
59
- },
60
-
61
- writeFileSync(...args) {
62
- console.warn('sync call')
63
- return fs.writeFileSync.apply({}, args)
64
- },
65
-
66
- writeFile(...args) {
67
- return fs.promises.writeFile.apply({}, args)
68
- },
69
-
70
- async readdir(...args) {
71
- return fs.promises.readdir.apply({}, args)
72
- },
73
-
74
- unlinkSync(...args) {
75
- console.warn('sync call')
76
- return fs.unlinkSync.apply({}, args)
77
- },
78
-
79
- mkdirpSync,
80
-
81
- async mkdir(path) {
82
- return fs.promises.mkdir(path)
83
- },
84
-
85
- async readFile(path) {
86
- return fs.promises.readFile(path, 'utf8')
87
- },
88
-
89
- statSync,
90
-
91
- readdirSyncRecursive(path) {
92
- console.warn('sync call')
93
- return tools.readdirSyncRecursive(fs, path)
94
- },
95
-
96
- readdirSync(path) {
97
- console.warn('sync call')
98
- return fs.readdirSync(path, { withFileTypes: true })
99
- },
100
-
101
- sanitizeFileName(fileName, replaceSpacesWith) {
102
- // Remove markdown emoji
103
- fileName = fileName.replace(/:\w+:/g, '').trim()
104
- fileName = sanitize(fileName)
105
- if (replaceSpacesWith)
106
- fileName = fileName.replace(/ /g, replaceSpacesWith)
107
- return fileName
108
- },
109
-
110
- preparePathForWriting(path) {
111
- let stat = statSync(path)
112
- if (!stat) {
113
- let { dir, ext } = _path.parse(path)
114
- if (!ext) {
115
- dir = path
116
- }
117
- mkdirpSync(dir)
118
- stat = statSync(path)
119
- }
120
- return {
121
- isFile: stat && stat.isFile(),
122
- isDirectory: stat && stat.isDirectory()
123
- }
124
- }
125
- }
126
-
127
- module.exports = gateway
@@ -1,35 +0,0 @@
1
- var wget = require('download');
2
-
3
- module.exports = download;
4
-
5
- async function download(repo, dest) {
6
- var url = github(normalize(repo));
7
- return wget(url, dest, { extract: true, strip: 1 })
8
- }
9
-
10
- function github(repo){
11
- return 'https://github.com/'
12
- + repo.owner
13
- + '/'
14
- + repo.name
15
- + '/archive/'
16
- + repo.branch
17
- + '.zip';
18
- }
19
-
20
- function normalize(string){
21
- var owner = string.split('/')[0];
22
- var name = string.split('/')[1];
23
- var branch = 'master';
24
-
25
- if (~name.indexOf('#')) {
26
- branch = name.split('#')[1];
27
- name = name.split('#')[0];
28
- }
29
-
30
- return {
31
- owner: owner,
32
- name: name,
33
- branch: branch
34
- };
35
- }
@@ -1,168 +0,0 @@
1
- const checkbox = require('markdown-it-checkbox')
2
- const imageSize = require('markdown-it-imsize')
3
- const emoji = require('markdown-it-emoji')
4
- const mark = require('markdown-it-mark')
5
- const removeMD = require('remove-markdown')
6
- const path = require('path');
7
-
8
- const MarkdownIt = require('markdown-it')
9
- let _platform = process.platform
10
-
11
- function extractWikilinkTopics(markdown) {
12
- const wikilinkRegex = /\[\[([a-zA-Z0-9\u00C0-\u017F/_\-. ]+)(?:\|([^\]]+))?\]\]/g;
13
- const topics = [];
14
- let match;
15
-
16
- while ((match = wikilinkRegex.exec(markdown)) !== null) {
17
- topics.push(match[1].trim()); // Always extract the topic (first capture group)
18
- }
19
-
20
- return topics;
21
- }
22
-
23
- function getRenderer(filePath) {
24
- const md = new MarkdownIt({html: true, breaks: true})
25
-
26
- md.use(checkbox)
27
- .use(mark)
28
- .use(emoji)
29
- .use(imageSize)
30
- .use(obsidianTopicLinks(filePath))
31
- .use(replaceImagePaths(filePath))
32
- .use(replaceLinkPathsAndTitles(filePath))
33
- .validateLink = () => true
34
-
35
- return md
36
- }
37
-
38
- function obsidianTopicLinks(filePath) {
39
- return function(md) {
40
- const obsidianLinkRegex = /^\[\[([a-zA-Z0-9\u00C0-\u017F/_\-. ]+)(?:\|([^\]]+))?\]\]/; // No 'g' flag
41
-
42
- function obsidianLinkRenderer(state, silent) {
43
- const pos = state.pos;
44
- const match = state.src.slice(pos).match(obsidianLinkRegex); // Always start from `pos`
45
-
46
- if (!match) return false;
47
- if (silent) return true; // Don't process further in silent mode
48
-
49
- const fullMatch = match[0];
50
- let topic = match[1].trim();
51
- const alias = match[2] ? match[2].trim() : topic;
52
- if (!topic.endsWith('.md')) topic = `${topic}.md`;
53
- const unencodedHref = resolveFileUrl(topic, filePath);
54
- const href = encodeURI(unencodedHref);
55
-
56
- // Create a new token
57
- const token = state.push("obsidian_link", "", 0);
58
- token.content = `<a href="${href}" title="${unencodedHref}">${md.utils.escapeHtml(alias)}</a>`;
59
-
60
- // Move parsing position forward
61
- state.pos += fullMatch.length;
62
- return true;
63
- }
64
-
65
- function render(tokens, idx) {
66
- return tokens[idx].content;
67
- }
68
-
69
- md.inline.ruler.before("link", "obsidian_link", obsidianLinkRenderer);
70
- md.renderer.rules.obsidian_link = render;
71
- }
72
- }
73
-
74
-
75
- function replaceImagePaths(filePath) {
76
-
77
- return function(md) {
78
- const defaultRender = md.renderer.rules.image || function(tokens, idx, options, env, self) {
79
- return self.renderToken(tokens, idx, options);
80
- };
81
-
82
- md.renderer.rules.image = function(tokens, idx, options, env, self) {
83
- const token = tokens[idx];
84
- const srcIndex = token.attrIndex('src');
85
- if (srcIndex >= 0) {
86
- const src = token.attrs[srcIndex][1];
87
- const srcUrl = !isUrl(src) && resolveFileUrl(src, filePath)
88
- if (srcUrl) token.attrs[srcIndex][1] = srcUrl;
89
- }
90
-
91
- return defaultRender(tokens, idx, options, env, self);
92
- };
93
- }
94
- }
95
-
96
- function replaceLinkPathsAndTitles(filePath) {
97
-
98
- return function(md) {
99
- const defaultRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
100
- return self.renderToken(tokens, idx, options);
101
- };
102
-
103
- md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
104
- const token = tokens[idx];
105
- const srcIndex = token.attrIndex('href');
106
- if (srcIndex >= 0) {
107
- const src = token.attrs[srcIndex][1];
108
- const srcUrl = !isUrl(src) && resolveFileUrl(src, filePath)
109
- if (srcUrl) token.attrs[srcIndex][1] = srcUrl;
110
- }
111
-
112
- // set the title to the href if it's not already set
113
- const titleIndex = token.attrIndex('title');
114
- if (titleIndex < 0) {
115
- const title = token.attrs[srcIndex][1];
116
- token.attrPush(['title', title]);
117
- }
118
- return defaultRender(tokens, idx, options, env, self);
119
- };
120
- }
121
- }
122
-
123
- function isUrl(href) {
124
- try {
125
- new URL(href);
126
- return true;
127
- } catch (e) {
128
- return false;
129
- }
130
- }
131
-
132
- function resolveFileUrl(src, filePath) {
133
- const dirname = _platform === 'win32' ? path.win32.dirname : path.dirname;
134
- const resolve = _platform === 'win32' ? path.win32.resolve : path.resolve;
135
-
136
- if (src.startsWith('file://')) return src;
137
- if (/^\.?\/$/.test(src)) src = './';
138
- const srcDir = dirname(filePath);
139
- const srcPath = resolve(srcDir, src) // filePath ? path.join(filePath, src) : path.resolve(src);
140
- const srcUrl = pathToFileURL(srcPath);
141
- if (src.endsWith('/')) return srcUrl + '/';
142
-
143
- return srcUrl;
144
-
145
- }
146
-
147
- function pathToFileURL(absolutePath) {
148
- if (_platform === 'win32') {
149
- absolutePath = '/' + absolutePath.replace(/\\/g, '/');
150
- }
151
- return `file://${absolutePath}`;
152
- }
153
-
154
- function renderCancelledTasks(markdown) {
155
- return markdown.replace(/- \[-\] (.+)/gm, '- :no_entry_sign: ~~$1~~');
156
- }
157
-
158
- module.exports = {
159
- _setPlatform(platform) {
160
- _platform = platform
161
- },
162
- renderMarkdown (markdown, filePath) {
163
- markdown = renderCancelledTasks(markdown)
164
- return getRenderer(filePath).render(markdown)
165
- },
166
- extractWikilinkTopics,
167
- removeMD
168
- }
@@ -1,10 +0,0 @@
1
- const chrono = require('chrono-node')
2
-
3
- module.exports = {
4
- replaceDateLanguage(text, asDate) {
5
- return text.replace(/\(?\${(.*?)}\)?/g, (match, p1) => {
6
- const date = chrono.parseDate(p1)
7
- return date ? date.toISOString() : p1
8
- })
9
- }
10
- }