Skip to content

refactor, feat: support notationHightligh (close #50), feat: editing in live preview (close #19, about #44) #51

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

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

LincZero
Copy link

@LincZero LincZero commented May 18, 2025

There are currently some problems with this PR:

This PR works:

TODO:

  • enhance
    • Excessive compilation size (This problem exists after the shiki version upgrade, and use from 'shiki' replace from 'shiki.mjs') (Because of the problems with bun and npm)
    • It might be necessary to add a new switch option.
    • a short-key to switch the current code block to the original state.
  • fix
    • editing in preview, should auto save
    • edit button z-index to low
    • meta highlight invalid
    • Fail to align when the last line is an blank line
    • black line zero height, influence background coloring
    • indent: match
    • indent: render, no treatment tabindex
    • edit: press tab key
  • feat
    • new option: allow custom language-type (langAlias, like dateview, dateviewjs, ...)
    • There is no need to edit the line where languageType is located in real time. This requires creating an independent textarea, just like typora.
  • docs
  • other
    • Just code2html directly, this might be a problem? (I'm not sure. At present, it seems that there aren't any problems. I'm not sure what the use is for those codes that I chose to jump out in advance and didn't use)

I'm trying to solve them. So currently, this PR is not a state that can be merged.

close #50
close #19
close #1
about #44

@LincZero LincZero changed the title feat: support notationHightligh (close #50) feat: support notationHightligh (close #50), feat: editing in live preview (about #44) May 19, 2025
@LincZero
Copy link
Author

LincZero commented May 19, 2025

QQ2025520-133147.mp4

I referred to the textarea on the https://shiki.style/ page. The principle is to stack textarea and pre together.

Warning

This strategy has a drawback: it is very susceptible to the influence of themes/plugins/styles, etc. Because it is necessary to ensure that the textarea and pre overlap perfectly; otherwise, the editing experience will not be good.

It's still the same display:

cebe2932502e47114ccb75f366379fc1

@LincZero LincZero changed the title feat: support notationHightligh (close #50), feat: editing in live preview (about #44) refactor, feat: support notationHightligh (close #50), feat: editing in live preview (about #44) May 19, 2025
@LincZero LincZero changed the title refactor, feat: support notationHightligh (close #50), feat: editing in live preview (about #44) refactor, feat: support notationHightligh (close #50), feat: editing in live preview (close #19, about #44) May 20, 2025
Copy link
Owner

@mProjectsCode mProjectsCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain more closely what you are doing and why you are doing it. Please keep to existing coding conventions used in the plugin, please use the set-up formatter, and please keep comments to english.

// - span
// - pre
// - textarea
const div = document.createElement('div'); el.appendChild(div); div.classList.add('obsidian-shiki-plugin')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the DOM manipulation methods provided by Obsidian to make this more concise.

'spellcheck': 'false',
};
Object.entries(attributes).forEach(([key, val]) => {
textarea.setAttribute(key, val);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add style attributes via JS. Use CSS classes.

src/main.ts Outdated
textarea.setAttribute(key, val);
});
// async part
this.codeblock_getPre(language, source).then(pre => span.innerHTML = pre);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid .innerHTML if possible

src/main.ts Outdated
@@ -102,9 +111,69 @@ export default class ShikiPlugin extends Plugin {
}
}

const codeBlock = new CodeBlock(this, el, source, language, ctx);
let option: 'pre'|'old'|'textarea' = 'textarea' // TODO as a new setting option
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this into a separate method.

Copy link
Author

@LincZero LincZero May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already made it clear at the beginning that this is not a PR that can be merged at present. All of these were written by me in "TODO".

Here it is written in todo: This will be a new option

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Since this is not a draft PR, I assumed you wanted this to be reviewed and merged.

Copy link
Author

@LincZero LincZero May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried draft pr. I didn't know there was this function.

I thought it would be enough to explain this matter at the beginning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm more concerned about is that here I didn't use most of the original code logic for rendering. I didn't use codeToToken but directly codeToHtml.

Was there any consideration in following the original logic?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the CM6 plugin the plugin applies the styles encoded in the tokens to existing elements.

@LincZero LincZero marked this pull request as draft May 20, 2025 09:34
@LincZero LincZero requested a review from mProjectsCode May 20, 2025 10:20
@LincZero
Copy link
Author

LincZero commented May 20, 2025

I pressed the wrong… 😢 don't review for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants