Skip to content
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

Bug: JS code cannot be folded and has highlight problems sometimes #249

Open
ZIV-LY opened this issue Apr 8, 2024 · 10 comments
Open

Bug: JS code cannot be folded and has highlight problems sometimes #249

ZIV-LY opened this issue Apr 8, 2024 · 10 comments
Assignees
Labels
bug Something isn't working needs info More information is required needs repro Needs reproduction

Comments

@ZIV-LY
Copy link

ZIV-LY commented Apr 8, 2024

Describe the bug

  1. JavaScript code cannot be folded sometimes even though I input the fold and the title shows "folded code". I close and reopen the note, the code block is open again.
  2. Sometimes the code block has highligh problem in Javascript code. I thought it may be there is === and !== in the Javascript code.

Screenshots

image

Thank you for your help!

@ZIV-LY ZIV-LY added the bug Something isn't working label Apr 8, 2024
@mayurankv
Copy link
Owner

Oh that is very weird! Could you provide the raw markdown for some code that doesn't fold please! (as many examples as you have would be great!)

@evensolberg
Copy link

evensolberg commented May 8, 2024

Any code with == in it gets highlighted, as that is the Markdown code to highlight. I'm seeing the same problem with Rust code.

Example:

let logits = logits.squeeze(0).unwrap().squeeze(0).unwrap().to_dtype(DType::F32).unwrap();
let logits = if self.repeat_penalty == 1.0 {
    logits
} else {
    let start_at = tokens.len().saturating_sub(self.repeat_last_n);
    candle_transformers::utils
        ::apply_repeat_penalty(&logits, self.repeat_penalty, &tokens[start_at..])
        .unwrap()
};

This turns on highlighting until the next == is found. Collapsing the code block hides the problem.

@mayurankv
Copy link
Owner

I'm unable to replicate the highlighting. Can I ask whether you are aware of any settings or plugins that could affect this? Are you able to replicate it in a sandbox vault? Would appreciate any further info!

@mayurankv
Copy link
Owner

Also is this in reading mode, editing mode or both?

@mayurankv mayurankv added needs repro Needs reproduction needs info More information is required labels May 13, 2024
@ZIV-LY
Copy link
Author

ZIV-LY commented May 14, 2024

Sorry for the confusion. I find it is not just because of "===". The following is the test code. Please have a try:

const rehearse = true; // Set this to false to actually make changes
const moveToTop = false; // Set this to true to move to top instead of deleting. This can help make "extra" sortable.

var fieldName = "extra";

// Choose the patterns to remove by uncommenting the following lines
var remPattens = [];
remPattens.push(new RegExp("^Citations \\(.+\\):", "i"));  // Citation pattern from zoterocitationcounts
remPattens.push(new RegExp("^\\d+ citations \\(.+\\)", "i")); // Citation pattern from zoterocitationcounts
remPattens.push(new RegExp("^ZSCC:.*$", "i")); // ZSCC: 000000
remPattens.push(new RegExp("^\\d+\\s*$", "i")); // 000000
// remPattens.push(new RegExp("^.+", "i")); // Uncomment this to completely wipe out the field

var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search();
s.libraryID = ZoteroPane.getSelectedLibraryID();
var ids = await s.search();
if (!ids.length) {
    return "No items found";
}
msg += 'the "'+fieldName+'" field will change from: \n' + currentVal + '\n === TO ====> \n' + newValue;
update_counter = 0;
// ids = ids.slice(0, 100); // To try out only on the first 10 items
await Zotero.DB.executeTransaction(async function () {
    for (let id of ids) {
        let item = await Zotero.Items.getAsync(id);
        let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
        let thisFieldName = mappedFieldID ? mappedFieldID : fieldID;
        let currentVal = item.getField(thisFieldName);
        let lines = currentVal.split("\n");
        for (let remPathern of remPattens){
            let lines_match = lines.filter(ex => remPathern.test(ex));
            let lines_nomatch = lines.filter(ex => !remPathern.test(ex));
            if (moveToTop){
                lines = lines_match.concat(lines_nomatch);
            } else { // Delete
                lines = lines_nomatch;
            }
        }
        newValue = lines.join("\n");
        if (currentVal!=newValue){
            if (rehearse){
                let title = item.getField('title');
                let msg = 'This is just a rehearsal. If your run this, \nfor item with title "'+title+'",\n';
                msg += 'the "'+fieldName+'" field will change from: \n' + currentVal + '\n === TO ====> \n' + newValue;
                if (!confirm(msg)) return;
            } else {
                update_counter += 1;
                item.setField(thisFieldName, newValue);
                await item.save();    
            }
        }
    }
});
msg += 'the "'+fieldName+'" field will change from: \n' + currentVal + '\n === TO ====> \n' + newValue;
return update_counter + " of the total " + ids.length + " item(s) updated";

Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test

msg += 'the "'+fieldName+'" field will change from: \n' + currentVal + '\n === TO ====> \n' + newValue;

@mayurankv
Copy link
Owner

Thank you I will give this a try and let you know!

@sjhsbhqf
Copy link

sjhsbhqf commented Jan 9, 2025

When I was recording Thinking Claude's cues in my notes using collapsible code blocks, I encountered some bugs.

Here is the beginning of the prompt word. Rendering is fine
image

After a flag with a ``` in the middle, then it can't be rendered:
image

@mayurankv
Copy link
Owner

This is still an outstanding issue I need to come back to, but for the second issue with the ``` flag, is this not expected behaviour in Obsidian? Does it work without the plugin (i.e. the codeblock continues otherwise?). I was under the impression that the nested inner codeblocks should have less backticks, i.e. the outer codeblock should be started with 4 backticks

@sjhsbhqf
Copy link

sjhsbhqf commented Jan 10, 2025

@mayurankv
Hello, I noticed that if the code styler plugin is disabled, the rendering effect in the two images above changes to the two images below, showing a continuous rendering effect.
image

image

So I think it should be allowed to exist such code blocks.

If you want to test it out, you can check this project: https://github.com/richards199999/Thinking-Claude

it is in the model instructions directory.

@mayurankv
Copy link
Owner

This should be addressed in the latest refactor. When that is pushed, I'll update here, then let me know if its still an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs info More information is required needs repro Needs reproduction
Projects
None yet
Development

No branches or pull requests

4 participants