Break Markdown: Option to change default tab / indent behavior / Do not create code block

Use case or problem

In most of the daily writing I do in my notes, I use tabs for formatting and emphasis. For example, I keep a list of poems in a common place book, and poetry often requires hard tabs to honor the poet’s construction. Right now, tabbing automatically parses to a code block

Proposed solution

Provide an option in the editor settings to toggle whether tabs convert to code block.

Current workaround

Some kind forum members have suggested using CSS, but I think this is a change that should be made (if possible) at the parser level.

7 Likes

Sadly this would diverge from the markdown spec. If you never use code blocks, it is probably best to use CSS styling for code blocks as poetry.

Otherwise see e.g., Center text for selected notes (Poetry collection) [CSS].

Right. I’m thinking here though of an option (or maybe it could be a plugin?) in the editor to disable this for non-code writing. Something that would be handled I think in the parser.

Similar to Ulysses allowing different Markdown settings

Or how Brett Terpstra has built in a similar preference for Marked 2

Just to clarify: I’m not really looking for an option to style the output of poetry (I’ll do this through Marked), but rather a way to change the behavior of tabs in the editor, so that they do not default to a code block.

It seems to me, and I could be wrong, that many note takers and writers who do not primarily work with code would benefit from this as an option.

1 Like

+1

I have many notes with indents which should not default to code.
Also, if there’s an empty line in between, the indent will default to code, see screenshot below.

If anybody found a solution, please let me know.

image

1 Like

@chrsle : In VSCode you can search and replace new lines while also using regex I think. I imagine you could do a mass search and replace using that tactic. In @akaalias documentation for pdf to markdown plugin he mentions using this

^([ ]|\t)+

when trying to rid lines of an extra space at beginning of some lines in the converted text. I think between adapting that and possibly using the VSCode ability to include returns in searches, you could put something together. Perhaps you don’t need the regex at all, but I would think you would need some.

Bottom line, it seems possible.

Good luck.

Thanks.

2 Likes

Thanks so much for your thoughtful response, really appreciate it! :+1:
Unfortunately I don’t know how to code, so I won’t be able to implement your solution.

Much rather than editing my notes, I would love to be able to turn off code blocks alltogether, but I have no idea of CSS and how to do that.

1 Like

Is there any existing CSS hack to turn off “indenting = code blocks”?

I don’t mind losing that markdown feature, as the is still the “````” way of doing it.

To be clear, you can’t disable the markdown feature, per se. You can edit how it appears so it doesn’t look like code anymore.

The exact CSS will depend on what the rest of your CSS is, however.

The “easiest” way is to open up your theme’s .css file, find the selector the theme uses to style paragraph text, and then add the code selector to that set of style instructions (I don’t know the selector offhand). Depending on how the CSS file is structured, however, this may not be straightforward.

Otherwise, you can custom-style this type of code. It looks like cm-hmd-indented-code is the selector, so you’re looking to add a snippet for something like:

.cm-hmd-indented-code {
    color: var(--text-normal);
    font: var(--text);
}

However, there’s a lot of assumptions baked into that snippet. It might work, it might not. You might want to look at some of the “getting started with CSS” stuff on the forum to be able to troubleshoot it!

1 Like

Thanks a lot for your reply. Good to know and sad to hear that it can’t be turned off. I imagine changing the appearance while leaving elements as code blocks, may cause troubles down the road with linking, transcluding etc.
Guess I’ll just have to adjust my writing style.
Thanks again for the clarification!

1 Like

The automatic code block coloring is an annoying feature. I’m trying to take notes, not write code. It seems like it should be a simple request. Editors like Atom don’t have this problem. I’d rather use Obsidian for the graph view, but the automatic code block highlighting has me seriously reconsidering. And from the forums I’m not the only one. Why can’t this be optional?

2 Likes

If this is true, please add to the previous feature request instead of creating a new one.

For what it’s worth, code blocks are a core part of markdown, and Obsidian is fundamentally a markdown editor. In fact, if you set up Atom as a markdown editor, it would also recognize code blocks.

Obsidian actually extends code blocks to make them more useful for people who do not use code. See e.g., the use of Mermaid for making diagrams, or various plugins’ use of code blocks to instantiate their features (e.g., dataview).

If you never use code, you could consider restyling generic code blocks to do something useful for you. Some users use code blocks to write and represent poetry, for example.

Obsidian will only create code blocks if the user types standard Markdown keystrokes for code blocks: back ticks or indents.

Avoid those and you should never see code-block colouring.

Angel

1 Like

I have the same problem. Documentation and video tutorials say that to indent a header, or a list item, you must press TAB. But when I do it, Obsidian 0.15.9 formats that header or list item as a block of code. How can I disable code insertion?

Thanks!

Can you share where you’re seeing this? It is not correct.

You cannot, I’m afraid. You may indent list items, but arbitrarily indentation is not possible in Markdown.

You may want to look into changing the style of code blocks so that you could use the functionality for something you’d want to show:

change color and font size of both ‘code block’ and inline code block in obsidian preview mode.

Hi @ryanjamurphy ,

thanks for the prompt replay and, first of all, a clarification:

when I say “indent” I ONLY and specifically mean “adding a level to the selected header”, the equivalent of manually typing another “#” character. Or, with list, to create sublists without typing manually another space before the asterisks. And by “outdent” I mean the opposite, that is select a header and move it one level up in the outline (or select a sublist and move it up to be part of the upper level list).

Now, I know that all this can (or could, last year) be done because I am watching this tutorial https://www.youtube.com/watch?v=6Hn1_UMTgPo

and I badly need to do exactly what that guy does, namely:

  • indent and outdent headers/paragraphs, and list items
  • swap lines or headers up and down

but (on Obsidian 0.15.9 on Ubuntu at least) I can only:

  • fold and unfold current paragraph
  • fold and unfold all paragraphs at once

but I cannot:

  • swap lines up or down (there are no “swap line” entries in the hotkeys panel)
  • indent or outdent, because the only effect of the TAB /Shift+TAB keys is to format as code block

thanks!

I’m not sure. Try setting up text the exact same way @nickmilo has set up the note in that video and play from there.

You cannot arbitrarily indent all content in markdown. All of the things Nick is working with are list items, which behave differently in terms of indentation. I didn’t see him indent paragraphs or headers the way you describe.

It’s been changed to “Move line up” / “[…] down”

Hi again, @ryanjamurphy .

Starting from the bottom…

thanks for the pointer to “Move line up/ down”, that’s solved.

About “arbitrarily indenting”: thanks for your explanation about lists, that’s useful, and works. But this discussion helped me to understand that what I actually need to do is outlining with HEADINGS, not lists.

That is, I need a way to:

UPDATE: I just discovered in this other video https://www.youtube.com/watch?v=0VdMfvppjFo

a partial, clunky but better-than-nothing answer to the questions below, that is "select all the text manually, THEN use “Move line up/down”. The question remains though:

  1. “grab” (preferably with hotkeys) any generic HEADING, together with all the paragraphs and sub-headings below it,
  2. drag and drop that whole block in any other place I want in the current outline (or should we say “Table of Contents”?)

Now, I see that if I click in the top right corner of the current note, and click on “Open Outline” I can do (1) above and only part of (2). I.e. I can grab, say, a level 2 heading, drag and drop it elsewhere in the outline pane, and all the text in the note will move accordingly.

But I cannot change heading level, that is I cannot grab a whole subchapter and drag it to the left, that is promote it to chapter. Or vice-versa. I can only move e.g. chapter 2.1 to become 1.1 or 3.1 And that is something I would really need to do.

So my original question becomes:

a) is it possible in the outliner pane to change LEVEL of a heading? Or is it manually typing or removing "#"s in the note source really the only way to do this?

b) are there any hotkeys to move headings around, in the note itself or in its outliner, or is it possible only with the mouse?

Thanks!

I imagine there are some options for this in the community plugins, but I don’t know which ones. You may want to post a Help thread here and/or ask on Discord.

1 Like

That is so f…ing crazy…
I’m a developer and I have thousands of notes where I format that like:
__Common things

__Comment
	//an one line commentthread
	/*multi lines comment*/
	
__Case-sensitive	
	C# is case sensistive(variable and keywords)

And I can’t use your editor normally because it translates everything to code… What is the problem with providing that toggle to turn that f***cking feature off!?!
I believe there is thousands of users that do not use your editor due to this reason. As I do…