obsidianmd / obsidianmd/obsidian-developer-docs
Decoration sample update for Lezer complex node structure
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 521
- Forks
- 174
- PR merge metrics
- No merged PRs in 30d
Description
https://docs.obsidian.md/Plugins/Editor/Decorations
After testing, I found that one line of Markdown note will be converted into multiple nodes (things like list-1, list-1_trailing_space, and list-1_string_url). Even a single list-x node may appear multiple times. Hence, I suggest updating the sample code to conform to the complex rendering behavior in practice.
Original code snippet:
enter(node) {
if (node.type.name.startsWith('list')) {
// Position of the '-' or the '*'.
const listCharFrom = node.from - 2;
builder.add(
listCharFrom,
listCharFrom + 1,
Decoration.replace({
widget: new EmojiWidget(),
})
);
}
},
Modified code snippet:
const handledLines = new Set<number>();
for (let { from, to } of view.visibleRanges) {
syntaxTree(view.state).iterate({
from,
to,
enter(node) {
try {
if (node.type.name.match('^list-[1-9]$')) {
const line = view.state.doc.lineAt(node.from);
if(!line.text.trim().startsWith('- ') && !line.text.trim().startsWith('* ')){
return;
}
if(handledLines.has(line.number)){
return;
}
handledLines.add(line.number);
// Calculate leading spaces for Markdown list indentation.
let leadingSpace = line.text.length - line.text.trimStart().length;
const markerPos = line.from + leadingSpace;
builder.add(
markerPos,
markerPos + 1,
Decoration.widget({ widget: new EmojiWidget() })
);
}
} catch (e) {
}
},
});
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Decorations page linked in the issue and locate the original list-node decoration sample in the documentation source. Compare its assumptions with the reported Lezer node structure and update the sample so it handles repeated and nested list nodes; verify the rendered example matches the expected decoration behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100