-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged preview extension #86
Merged
kortina
merged 5 commits into
kortina:ak-files-for-wiki-link-ref-from-cache-sync
from
thomaskoppelaar:ak-files-for-wiki-link-ref-from-cache-sync
Sep 17, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b439714
Merged preview code
thomaskoppelaar 154bc3b
Moved Render plugin code to own file
thomaskoppelaar 70dd6ea
showFileExtensionInPreview -> previewShowFileExtension
thomaskoppelaar 77af819
Moved plugin settings into own function
thomaskoppelaar 5570958
Moved plugin settings into own function
thomaskoppelaar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { MarkdownDefinitionProvider } from './MarkdownDefinitionProvider'; | ||
import { NoteWorkspace } from './NoteWorkspace'; | ||
import { RefType } from './Ref'; | ||
|
||
// See also: https://github.com/tomleesm/markdown-it-wikilinks | ||
// Function that returns a filename based on the given wikilink. | ||
// Initially uses filesForWikiLinkRefFromCache() to try and find a matching file. | ||
// If this fails, it will attempt to make a (relative) link based on the label given. | ||
export function PageNameGenerator(label: string) { | ||
const ref = { | ||
type: RefType.WikiLink, | ||
word: label, | ||
hasExtension: false, | ||
range: undefined | ||
} | ||
const results = MarkdownDefinitionProvider.filesForWikiLinkRefFromCache(ref, null); | ||
|
||
label = NoteWorkspace.stripExtension(label); | ||
|
||
// Either use the first result of the cache, or in the case that it's empty use the label to create a path | ||
let path: string = (results.length != 0) ? results[0].path : NoteWorkspace.noteFileNameFromTitle(label); | ||
|
||
return path; | ||
} | ||
|
||
// Transformation that only gets applied to the page name (ex: the "test-file.md" part of [[test-file.md | Description goes here]]). | ||
export function postProcessPageName(pageName: string) { | ||
return NoteWorkspace.stripExtension(pageName); | ||
} | ||
|
||
// Transformation that only gets applied to the link label (ex: the " Description goes here" part of [[test-file.md | Description goes here]]) | ||
export function postProcessLabel(label: string) { | ||
// Trim whitespaces | ||
label = label.trim(); | ||
|
||
// De-slugify label into whitespaces | ||
label = label.split(NoteWorkspace.slugifyChar()).join(" "); | ||
|
||
if (NoteWorkspace.previewShowFileExtension()) { | ||
label += `.${NoteWorkspace.defaultFileExtension()}`; | ||
} | ||
|
||
switch (NoteWorkspace.previewLabelStyling()) { | ||
case "[[label]]": | ||
return `[[${label}]]`; | ||
case "[label]": | ||
return `[${label}]`; | ||
case "label": | ||
return label; | ||
} | ||
; | ||
} | ||
|
||
export function pluginSettings(): any { | ||
return require('@thomaskoppelaar/markdown-it-wikilinks')({ | ||
generatePageNameFromLabel: PageNameGenerator, | ||
postProcessPageName: postProcessPageName, | ||
postProcessLabel: postProcessLabel, | ||
uriSuffix: `.${NoteWorkspace.defaultFileExtension()}`, | ||
description_then_file: NoteWorkspace.pipedWikiLinksSyntax() == "desc|file", | ||
separator: NoteWorkspace.pipedWikiLinksSeparator(), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a separate repo, or should some of this code be moved in as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's best to keep this separate - We can override practically all settings / functions from within
require('@thomaskoppelaar/markdown-it-wikilinks')({})
, and people may want to use this themselves for exporting / rendering for their own personal use cases.