Giter Club home page Giter Club logo

obsidian-better-codeblock's Introduction

Obsidian Better Code Block

This is a plugin for Obsidian (https://obsidian.md).

Most of the code in this plugin comes from the following two plugins (thanks to their contributions), and the icons are from Admonition.

https://github.com/tadashi-aikawa/obsidian-embedded-code-title

https://github.com/nyable/obsidian-code-block-enhancer

I have merged the code in both plugins and modified some of their functionality.

Features

Enhancer the markdown code block in preview mode. Add title, line number, highlight to code blocks, you can click on the title to collapse or expand the block.

In version 1.0.5, use the syntax in the diagram below to set the block title, highlight, fold

  • Use TI:"your title" to add title
  • Use HL:"numbers" to add highlight, such as HL:"1,2,3", HL:"1-3", separate by ,
  • Use "FOLD" to set the default fold

If you have a better idea, please submit an issue

image20220606011534.png

In version 1.0.4, add the language in the top right, like this: screenshots/image-20220601202203.png

Known issues

  • Sometimes the auto linefeed error, can be solved by switching the preview mode once
  • The PDF export cannot be auto linefeed

Manually installing the plugin

  • Copy over main.js, styles.css, manifest.json to your vault VaultFolder/.obsidian/plugins/obsidian-better-codeblock/.

obsidian-better-codeblock's People

Contributors

stargrey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

obsidian-better-codeblock's Issues

bug/issue

This plug in causes the PDF generation to create blank pages

Use of !important in style sheet breaks css for other things

In your second styling element, you used an !important for the margin of the copy button. This makes the copy button perform this function across the entire vault and other plugins, including within things like notes, notices, etc. that use the "code-block" functionality. Also, the .copy-code-button is very broad. Could you make it more specific to the classes you are using in your plugin?

Code previously
.copy-code-button{
margin-top: 42px !important; /* 为自带的按钮增加上边距 */
}

Changes I made to make the plugin compatible with the rest of my plugins.
pre[class*="code-block-pre"] .copy-code-button{
margin-top: 42px; /* 为自带的按钮增加上边距 */
}

One thing I did not take the time to do is do this for every class type. I only did it for the situation where all three settings have been turned on for the plugin.

Thanks for all the hard work. I really enjoy using your plugin 😄

iPad update seems stuck

1.0.1 seems to update, but the version never changes to 1.0.2, so it constantly re-updates—
iPadPro,v.15.5

能否与vscode mpe插件的{.line-numbers}保持一致

在VSCODE中,有Markdown Preview Enhanced插件,在后加上{.line-numbers}即可显示代码行号。
能否将当前ob插件的添加行号功能与MPE保持一致?

import ...

public class abc {
}

有这个 {.line-numbers}就显示行号(无论插件中是否设置),没有,可以按插件里的设置执行。
或者,直接取消插件中的设置,仅以此为准(可能会造成新旧版本不兼容,所以,保留原有设置,加入新功能比较好。)

谢谢!

Feature Request: make it work in Live Preview

It took me like 20 minutes to realize that the plugin was not broken. It just doesnt work in Live Preview.
As I never use the reading mode for anything (as is probably the case with many people), it would be really awesome to see this work in Live Preview.

Thank you.

Fix request: code line number goes wrong then single line is too long

Hi there, thanks for introducing this plugin!

Recently i discover that, when a single line of code is too long,
obsidian will display it into two or more lines,
but logically they belong to one line of markdown(line number of obsidian proves that).

However, this plugin will not skip the overflow content, instead, it will continue to label line number, casuing the line number goes wrong.

I intentionally squeeze the width of obsidian to make it more obvious.
image

Sincerely thanks if you could look into it : )

Fix Request: cannot export to pdf due to this plugin

Hi there, thanks for bringing this plugin and i really love it.
However, when i tried to Exported to PDF as i often do, it tells me failed to export.

I checked console section is developer's mode, traceback mentioned this plugin.
A markdown document without any codeblock can be exported successfully.
Maybe it caused by other plugins other than this one, but i have no idea what's happening.

Sincerely hope you could help. Exported to PDF is a function i use much often to create handouts.
Thanks in advance!

Error screenshot:
img
Code that mentioned in the trackback of this plugin:

  let codeBlockFirstLine = view.editor.getLine(codeBlock.lineStart);

comments line break

This code in edit-mode

image

is this in view mode

image

The comment seems to be broken
There is a vertical line and numbering ends.

Bug: Character Escaping

I noticed that using <?php in the code block is problematic for line numbers, title, and even the highlighted lines as they start behaving weirdly in many ways. I suppose there are some escaping issues around. The same happens if the $ sign exists in the code.

Feature request: leading icons for filename-typed titles, and 2 bugs found

@lethefrost
I'm a little confused about what you mean. Under what circumstances will there be a form like filename.extension? Could you describe it in detail?

This was actually a mistake on my part, but I didn't fix it because I thought these left blank spaces would indicate a collapsed section below the code block.

If you don't like it, you can put this code in style.css or your CSS snippets to close this effect

pre[class*=language-].code-block-pre__has-linenum {
  padding-bottom: 0px;
}

Originally posted by @stargrey in #4 (comment)

Hi, Thank you for giving this css selector!

I am sorry that I might have not explained it clearly and caused you confusion. I made a screenshot to better describe a use case.

image

By the way, I just found two more bugs:

  1. Any title we add after the language indicator language:title will disable the code block language syntax highlighting in preview mode.
    • In live preview editor mode, the syntax highlighting is not affected by a :title following the language indicator (As in the attached screenshot below, in editor mode, the two kinds of title are both highlighted) image image
    • However, when we switch to preview mode, it is broken by having a title. image image
  2. If a line in the code block is very long to occupy the full width and triggers line wrap, the line number feature has a bug of alignment. Please see below. image

Feature Request: multiple highlight colors

Description: Support multiple highlight colors.
For example, the code block below specify the 2nd row is highlighted in red, the 3rd in green, the 4th in blue.

```java TI:"Hello World" HL:"R[2], G[3], B[4]"

It's userful when I want to highlight the change of code, like what github does.

Hover cosmetics

Thanks for your great plugin. I really missed something like this. ;-)

When I hover over the right arrow

image

i cannot reach the arrow, because I see this:

image

Can I do something to prevent this?

SYSTEM INFO:
Obsidian version: v1.1.16
Installer version: v1.1.16
Operating system: Windows 10 Home 10.0.19045
Login status: not logged in
Insider build toggle: off
Live preview: off
Legacy editor: off
Base theme: dark
Community theme: Minimal v6.3.2
Snippets enabled: 20
Restricted mode: off
Plugins installed: 75
Plugins enabled: 45
1: Buttons v0.4.19
2: Commander v0.5.0
3: Completr v3.1.3
4: Contextual Typography v2.2.4
5: Copy document as HTML v0.4.3
6: Dataview v0.5.55
7: Dictionary v2.22.0
8: Editor Syntax Highlight v0.1.3
9: Execute Code v1.8.1
10: Excel to Markdown Table v0.4.0
11: GPT-3 Notes v0.2.7
12: Janitor v1.0.7
13: Linter v1.12.0
14: Number Headings v1.13.0
15: Paste image rename v1.6.1
16: Style Settings v1.0.3
17: Symbols Prettifier v1.1.1
18: Templater v1.16.0
19: Vault Statistics v0.1.3
20: Minimal Theme Settings v6.3.1
21: Pandoc Plugin v0.4.1
22: Icon Folder v1.7.0
23: Hover Editor v0.11.9
24: Media Extended v2.11.1
25: Editing Toolbar v2.3.1
26: Omnisearch v1.14.0
27: Recent Files v1.3.5
28: Remember cursor position v1.0.7
29: Chronology v1.1.4
30: Text Extractor v0.4.3
31: Supercharged Links v0.9.6
32: Obsidian Enhancing Export v1.2.1
33: Bulk Rename v0.5.2
34: Obsidian Camera v1.5.0
35: Auto Glossary v0.9.0
36: ChatGPT MD v1.5.0
37: Show Current File Path v0.5.2
38: Tasks v3.4.0
39: Advanced URI v1.35.0
40: Homepage v3.0.2
41: Creases v0.6.6
42: Export Image plugin v1.0.3
43: Home tab v1.1.2
44: Unicode Search v0.3.0
45: Better CodeBlock v1.0.8

I can't get this to work at all

Hi! I'm pretty new to Obsidian so I may be doing something wrong. I installed this plugin through Obsidian (though I did then double-check that everything was in the .obsidian plugins folder as described in your "manual install" section). Under Community Plugins I have Restricted Mode turned off, and "Better CodeBlock" is listed at the bottom and it is turned on. The settings are the default. And yet when I type in the Hello World example from your README page, absolutely nothing happens: no line number, no title, no highlighting. Specifically, the first line of my codeblock starts with three backticks followed by JAVA TI:"Hello World" HL:"3"

I am running Obsidian v1.4.16 on a Mac. I have tried quitting and restarting Obsidian, and closing and reopening the Vault in question.

Is there something I'm missing? Thanks.

Better CodeBlock breaks obsidian PDF export function for notes with code blocks

If better code block Plugins is enabled the PDF export function of Obsidian creates only blank white pages.
Versions
MacOS: 13.4.1
Obsidian: 1.5.03
Better CodeBlock: 1.0.8

Re-Install of Obsidian and also Better CodeBlock does not help.
Creating a new vault also has no effect.
I can't see any error in the Obsidian Developer Console.

Feature request: Adding the language in the top right

Love the plugin so far, I take a lot of programming notes and this has made it all a lot nicer! I was wondering if it would be possible to add a toggle in the settings for displaying the language name in the top right corner of each code frame? (I use quite a few languages, and would find this very useful). Cheers for the great work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.