Skip to content

Commit

Permalink
Merge pull request #131 from 0xGG/feat/wikilink
Browse files Browse the repository at this point in the history
feat: Supported wiki link
  • Loading branch information
shd101wyy authored Jun 27, 2020
2 parents 098417d + 4c74796 commit 9bf4d52
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ note:

> You can still check the deprecated alpha version README.md [here](./README.alpha.md).
**Attention: Breaking updates coming soon. Please check [this GitHub issue](https://github.com/0xGG/crossnote/issues/129) for more information.**

https://crossnote.app

<a href="https://www.producthunt.com/posts/crossnote?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-crossnote" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=197331&theme=dark" alt="Crossnote - An interesting markdown note taking progressive web app | Product Hunt Embed" style="width: 250px; height: 54px;" width="250px" height="54px" /></a>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"automerge": "^0.14.0",
"chinese-conv": "^1.0.1",
"clsx": "^1.1.0",
"codemirror": "^5.54.0",
"codemirror": "^5.55.0",
"crypto-js": "^4.0.0",
"date-fns": "^2.12.0",
"diff3": "^0.0.3",
Expand Down Expand Up @@ -69,7 +69,7 @@
"unstated-next": "^1.1.0",
"urql": "^1.9.7",
"uuid": "^7.0.3",
"vickymd": "^0.2.3"
"vickymd": "^0.2.4"
},
"scripts": {
"git-info": "echo export default \"{\\\"logMessage\\\": \\\"$(git log -1 --oneline)\\\",\\\"hash\\\":\\\"$(git rev-parse HEAD)\\\"}\" > src/_git_commit.js",
Expand Down
14 changes: 12 additions & 2 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ import { formatDistance } from "date-fns";
import { getHeaderFromMarkdown } from "../utilities/note";
import {
printPreview,
openURL,
postprocessPreview as previewPostprocessPreview,
openURL,
} from "../utilities/preview";
import ChangeFilePathDialog from "./ChangeFilePathDialog";
import { SettingsContainer } from "../containers/settings";
Expand Down Expand Up @@ -644,7 +644,6 @@ export default function Editor(props: Props) {

useEffect(() => {
if (textAreaElement && !editor && note) {
// console.log("textarea element mounted");
const editor: CodeMirrorEditor = VickyMD.fromTextArea(textAreaElement, {
mode: {
name: "hypermd",
Expand All @@ -655,6 +654,17 @@ export default function Editor(props: Props) {
keyMap: settingsContainer.keyMap,
showCursorWhenSelecting: true,
inputStyle: "contenteditable",
hmdClick: (info: any, cm: CodeMirrorEditor) => {
let { text, url } = info;
if (info.type === "link" || info.type === "url") {
const footnoteRef = text.match(/\[[^[\]]+\](?:\[\])?$/); // bare link, footref or [foot][] . assume no escaping char inside
if (!footnoteRef && (info.ctrlKey || info.altKey) && url) {
// just open URL
openURL(url, note);
return false; // Prevent default click event
}
}
},
});
editor.setOption("lineNumbers", false);
editor.setOption("foldGutter", false);
Expand Down
22 changes: 19 additions & 3 deletions src/containers/crossnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ function useCrossnoteContainer(initialState: InitialState) {
}

const noteConfig: NoteConfig = {
id: "",
tags: tags,
modifiedAt: new Date(),
createdAt: new Date(),
Expand All @@ -447,7 +446,7 @@ function useCrossnoteContainer(initialState: InitialState) {
const note: Note = {
notebook: notebook,
filePath: filePath,
markdown: "",
markdown,
config: noteConfig,
};
setNotebookNotes((notes) => [note, ...notes]);
Expand Down Expand Up @@ -748,12 +747,29 @@ function useCrossnoteContainer(initialState: InitialState) {
const openNoteAtPath = useCallback(
(filePath: string) => {
if (!crossnote) return;

if (!filePath.endsWith(".md")) {
filePath += ".md";
}

const note = notebookNotes.find((n) => n.filePath === filePath);
if (note) {
_setSelectedNote(note);
} else {
createNewNote(
selectedNotebook,
filePath,
"# " + path.basename(filePath).replace(/\.md$/, ""),
);
}
},
[crossnote, notebookNotes, _setSelectedNote],
[
crossnote,
notebookNotes,
selectedNotebook,
_setSelectedNote,
createNewNote,
],
);

const loadAttachments = useCallback(async () => {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4485,10 +4485,10 @@ code-point-at@^1.0.0:
resolved "https://registry.npm.taobao.org/code-point-at/download/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=

codemirror@^5.54.0:
version "5.54.0"
resolved "https://registry.npm.taobao.org/codemirror/download/codemirror-5.54.0.tgz?cache=0&sync_timestamp=1589962970992&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcodemirror%2Fdownload%2Fcodemirror-5.54.0.tgz#82b6adf662b29eeb7b867fe7839d49e25e4a0b38"
integrity sha1-grat9mKynut7hn/ng51J4l5KCzg=
codemirror@^5.55.0:
version "5.55.0"
resolved "https://registry.npm.taobao.org/codemirror/download/codemirror-5.55.0.tgz?cache=0&sync_timestamp=1592745461049&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcodemirror%2Fdownload%2Fcodemirror-5.55.0.tgz#23731f641288f202a6858fdc878f3149e0e04363"
integrity sha1-I3MfZBKI8gKmhY/ch48xSeDgQ2M=

collection-map@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -16531,10 +16531,10 @@ [email protected]:
core-util-is "1.0.2"
extsprintf "^1.2.0"

vickymd@^0.2.3:
version "0.2.3"
resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.2.3.tgz#91deaa0632c190309f521a68570cf506bacdc7fc"
integrity sha1-kd6qBjLBkDCfUhpoVwz1BrrNx/w=
vickymd@^0.2.4:
version "0.2.4"
resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.2.4.tgz#c011e0c2f74e0f7906b52834460b6f7f68fb7427"
integrity sha1-wBHgwvdOD3kGtSg0Rgtvf2j7dCc=
optionalDependencies:
echarts "^4.7.0"
emojione "^4.5.0"
Expand Down

0 comments on commit 9bf4d52

Please sign in to comment.