-
Notifications
You must be signed in to change notification settings - Fork 30
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
Internal mermaid clickable links #33
base: main
Are you sure you want to change the base?
Conversation
@dionjwa thanks for this. Sorry for the slow response, we'll be digging out from our December hibernation for a while yet. Your need here puts a spotlight on our need for a plugin capability. My own product's even rarer needs -- embedding our ebook types -- also should be moved out to a plugin. I'm hopeful that I might be able to work on that next week. |
I think that plugins need:
It would definitely be possible move the mermaid URL processing into a plugin then and would avoid having to regex everything. |
Good point about ordering. I'm thinking that we can convert most of the existing transforms into plugins that are just enabled by default. If it exists
|
Those make a lot of sense. My feeling is with those options, plugin writers would have all they needed produce the final |
Just an update... I'm about halfway through restructuring everything, including all the built-in stuff, as plugins. Part of this change is to make it easy to write unit tests on plugins that don't have to hit actual Notion API. |
Sounds good, and I appreciate the update! I am in no rush because I am using my own local repo for this right now, and am happy to adapt this to the new plugin system once you're done. |
OK @dionjwa, the plugin stuff is now merged. Can you give it a try? See https://github.com/sillsdev/docu-notion/blob/main/src/plugins/README.md. For your custom mermaid slug, instead of a command-line argument, you'd put something in the new |
Hi @hatton I'm having trouble getting this this working.
import { IDocuNotionConfig, IPlugin, IDocuNotionContext, Log } from "docu-notion";
import { join} from "path";
// The mermaid interactive click syntax:
// https://mermaid.js.org/syntax/flowchart.html#interaction
// NB this processing is just for internal link navigation
// const linkRegExp = /\s*click\s+([A-za-z][A-za-z0-9_-]*)\s+"(https:\/\/www\.notion\.so\/\S*)"/g;
const linkNotionRegExp = /^(https:\/\/www\.notion\.so\/)(.*)/g;
// This is an example of a plugin that needs customization by the end user.
// It uses a closure to supply the plugin with the customization parameter.
const pluginName = "mermaidLinks";
function docunotionMermaidLinks(args:{slugPrefix:string}): IPlugin {
const {slugPrefix} = args;
return {
name: pluginName,
// corrections to links after they are converted to markdown
linkModifier: {
match: linkNotionRegExp, // does this plugin apply to this link?
convert: (
context: IDocuNotionContext,
markdownLink: string
) => {
Log.verbose(`[plugin ${pluginName}] markdownLink ${markdownLink}`);
console.log("mermaidLinks ", markdownLink)
return "fakelink";
}
},
};
}
const config: IDocuNotionConfig = {
plugins: [docunotionMermaidLinks({slugPrefix:"customParameter"})],
};
export default config; NB: I am setting the links to some fake link to check that this plugin is working. Command: node_modules/docu-notion/$(cat node_modules/docu-notion/package.json | jq -r .bin) --notion-token {{NOTION_TOKEN}} --root-page {{NOTION_DOCUMENT_ROOT}} --markdown-output-path $(pwd)/{{DOCU_NOTION_OUTPUT_PATH}} --log-level verbose I see the config loaded and the plugin detected:
But I don't see any processing by the plugin. console.logs don't work, and Log.verbose indicates that the plugin is not getting called. But the regex matches the links supplied. The mermaid diagram in my notion page looks like: graph LR
A[An internal page] -->|Get money| B(Go shopping)
click A "https://www.notion.so/metapages/Introduction-to-docu-notion-779f83504bd94642a9b87b2afc810a97"
The page link in the mermaid diagram is to a valid docu-notion page, as its processed and shows up in So my problems are:
|
Also: the |
Also: I run this process multiple times, for |
More: When I make a custom Synced code blocks are not populated, but one synced block is visible, the other is not. IE one version of the synced block is correctly shown in the final docs, but the other synced block is not shown. Both
|
I think the lack of data for synced blocks is what is blocking me. Correct links in mermaid diagrams are important, but the real value comes when I can create them and sync them across different places, which I cannot seem to get working here. I think if I had access to the configured notion client I could make these API calls myself |
Feedback about the plugin system:
There appears to be a bug with |
The plugin isn't being called because the regular expression in your code above was only matching on URLs, rather than the complete markdown link. This works for matching:
|
Well actually, two reasons. The other is that docu-notion isn't applying changes inside of code blocks, which normally would be what we want, right? The normal point of a code block is to say "take this literally, don't interpret it". Maybe we could reasonably say that link conversion should still happen within mermaid code blocks? |
I'm working on seeing if this would be an appropriate approach: const mermaidLinks: IPlugin = {
name: "mermaidLinks",
regexMarkdownModifications: [
{
regex: /```mermaid\n.*"(https:\/\/www\.notion\.so\S+)"/,
getReplacement: async (context: IDocuNotionContext, s: string) => {
return await context.convertNotionLinkToLocalDocusaurusLink(s);
},
},
],
}; That is,
|
OK, @dionjwa please see the branch If it is enough, then I can get that branch merged so that you can use this approach in a real plugin. |
If I check out that branch, and run |
@hatton I got the mermaid links plugin working on the latest alpha package. I've put together all the plugins I needed so that I got the results I needed, I hope they are helpful. Nice work! https://www.npmjs.com/package/@metapages/docu-notion-plugins |
Fixes #28
I use mermaid diagrams with clickable link to other notion documents:
You can click on "An internal page" and it takes you to another notion document.
This PR adds some config and processing to get those internal mermaid URLs working with docu-saurus.
I tried to make a
CodeTransformer
in the same pattern as the other transformers, but it didn't have the right context for getting the links path to the notion documents, so I just added a link processor.The result is the same mermaid diagrams but the links correctly link to docusaurus pages:
You can then click the first node and you go to another page.
There is an extra config flag, I was not able to figure out how to align the different docusaurus root documents you can specify (e.g.
./docs
,./blog
), with the docu-notion->saurus step, so some experimentation may be needed to align the paths and the slugs.This change is