typora-issues icon indicating copy to clipboard operation
typora-issues copied to clipboard

Support custom class and attributes for HTML blocks

Open CxRes opened this issue 5 years ago • 12 comments

To Replicate:

Add the following css to base.user.css or github.user.css

.left {
  color: red;
}

Start Typora and create a html block:

<div class="left">
    foo
</div>

The color of foo remains black.

When you inspect the code (in view mode, not editing mode), it is rendered as:

<div>
    foo
</div>

The attributes are missing. Consequently the style is not applied!

Typora 0.9.70 Windows 10 x64

CxRes avatar Apr 26 '19 07:04 CxRes

Are there any reason why the class attribute in inline HTML blocks will be filtered in the resulting HTML?

I would be happy if it will be supported.

tschroeter avatar May 23 '19 18:05 tschroeter

@tschroeter There are some “Historical Problems“ here since HTML is not supported from the beginning: We also use class for styling and logics, and we also import styling from 3rd libraries likebootstrap which add styles for class attributes. So before we separate all class we use from what users would use, we cannot enable class support.

abnerlee avatar May 26 '19 15:05 abnerlee

This works for me in the HTML export, but not in the Typora Preview of the Markdown. But my Typora version is a bit newer.

github.user.css .green{ background: rgba(0, 255, 0, 0.5); }

Markdown File <div class="green">some text with green background, that is not green in the Markdown Preview but in the exported HTML</div>

It would be cool if it would be able to already see the custom styles in the Preview.

Typora: version 0.9.72(beta) Windows 10 x64

toolchild avatar Jul 29 '19 12:07 toolchild

has this issue been resolved?

johnwry avatar Oct 13 '21 07:10 johnwry

has this issue been resolved?

Nope, not yet

abhitrueprogrammer avatar Nov 14 '21 18:11 abhitrueprogrammer

Is there a workaround?

wangyingang avatar Dec 10 '21 12:12 wangyingang

I found that <div class="test">content</div> would be rendered to a complicated (a nested <div> structure) HTML code snippet, and class="text" disappeared in the rendered output. I feel that rendering is a bit complicated and unpredictable.

Can we support custom class and attribute in the same way as python-markdown ? for example, This is a paragraph. {: #someid .someclass some_attribute='some_value' } will be rendered as <p id='someid' class='someclass' some_attribute='some_value'> This is a paragraph</p>.

tian-yan avatar Jan 10 '22 07:01 tian-yan

Struggling with the same to make highlighting more useful.

Putting the below in base.user.css as per: https://support.typora.io/Add-Custom-CSS/, but it is ignored when using the "MARK" tag.

/* DJS Highligh colors for mark element and spans */
mark, .hlyellow {
  background-color: rgb(2255, 247, 175);
}

.hlpink {
  background-color: rgb(255,191,206);
}

.hlblue {
  background-color: rgb(178,205,251);
}

.hlorange {
  background-color: rgb(255,215,174);
}

.hlgreen {
  background-color: rgb(169, 250, 169);
}

DarwinJS avatar Mar 10 '22 12:03 DarwinJS

Is this feature going to be added in the later versions?

Enigmatisms avatar Apr 17 '22 13:04 Enigmatisms

Can we support custom class and attribute in the same way as python-markdown ? for example, This is a paragraph. {: #someid .someclass some_attribute='some_value' } will be rendered as <p id='someid' class='someclass' some_attribute='some_value'> This is a paragraph</p>.

I've been wanting this for years as trying to use html breaks Markdown formatting inside html blocks (which defeats the purpose of using Typora, etc.). This would really solve a bunch of issues that currently keep me from using Markdown more often.

Ziflin avatar May 11 '22 17:05 Ziflin

I was hoping that the custom css https://support.typora.io/Add-Custom-CSS/ along with html support https://support.typora.io/HTML/ would give me the flexibility I needed. Unfortunately, the class attributes are not rendered in preview mode.

@abnerlee are there any workarounds? I wouldn’t mind targeting my css with obscure css selectors or data-attributes. It doesn’t matter if it’s hacky so long as it works.

jlarmstrongiv avatar Jun 06 '22 18:06 jlarmstrongiv

Found a workaround!

Give a supported tag a custom style, e.g.

<p style="-typora-class: eyebrow-text;">Workaround for custom classes</p>

Then, target that with attribute selectors, e.g.

[style*="-typora-class: eyebrow-text"] {
  color: green;
}

jlarmstrongiv avatar Jun 06 '22 19:06 jlarmstrongiv

Hello @jlarmstrongiv , Thanks for sharing the cool trick!

I've made my callouts following your idea 😄 . Check it here - https://gist.github.com/ajaxray/d5302dfe1418ef1c5b41e758225d8215

ajaxray avatar Dec 03 '22 13:12 ajaxray