You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and what are the costs? -.- In a cashed environment with heavy traffic it's a huge benefit! (and it's damn annoying if you have to put html code which you normally would split over several lines in the same line to prevent layout bugs, because HTML is NOT whitespace insensitive.
maintainability. additional options. i doubt you serve enough traffic where the savings would be noticeable - you'd have to be google or Facebook for the benefit to be HUGE. layout bugs with rendered markdown sounds like a CSS problem, which i've never had nor understand since most elements are block elements where whitespace is insignificant.
This will render a space between the two divs and this is normally not what you want in this situation. To prevent this behavior you have to write them in the same line. This sucks! …but it doesn't look like you are open to any reasonable Arguments. So whatever, I'll just open my own branch. cu
@jonathanong I have a good reason for this
I'm using marked inside a pre element since it's space sensitive, the margin dont get merged. I cannot remove newline on the resulting string because code block inside the markdown will loose their layout.
I had good reasons as well (…and of course I'm not using inline styles in real code) @jonathanong just seems to be totally unreasonable
Good luck at convincing him of anything.
I see no reasonable reason to remove the semantic information that whitespace can offer. This is especially true in the case of Markdown where by design you are encouraged to wrap lines. Maybe you wanted to make an editor that could enforce or alter a user's desired line wrap setting. I would also argue that it just makes better sense in terms of search-ability. I think it's a pretty sane choice to leave compression out rather than risk encouraging it.
I would also argue that compression has no real economic value any longer. Cloud keeps getting cheaper and mobile networks keep getting faster. If anything I would say the real enemy is the AMD pattern used in browser based development. It encourages an excess of connections which ultimately slow down a user's experience and adds more traffic.
If you really need to compress, just do it in a post process. I'm sure there has to be something out there to enable that.
If you compress your regular html it would be nice if the html output from markdown would be also compressed. I agree, its a must have feature. Some workaround already?
Was going to mark this as stale, but I'm curious if this is still a desired feature for folks actively using marked.
I see what @jonathanong is saying. I also think there are issues that come with interspersing Markdown and HTML. In some cases, it's better to just pick HTML. Or, compile and inject. With template string literals this could be pretty straightforward. But, I'm new around here still; so, I'll have to use pseudo-code.
If your markdown is coming from a database query, it shouldn't have HTML, in my opinion.
let markdown = 'Hello, World!`;
let html = marked.toHtml(markdown);
let final = `<div style="inline-block">${html}</div>`
That HTML is definitely strange but, looking at the broader point, knowing what the output is and the possible side-effects of that...anyway....
The drawback I see is the potential cost-benefit of doing something like this. For <code><pre></pre></code> we need to maintain whitespace. I don't know what the overhead would for stripping whitespace, on the fly, while ignoring the triple-backtick case.
This can easily be done with other tools after getting the uncompressed output from marked.
constminify=require('html-minifier').minify;constmarked=require('marked');constmd="some markdown";constresult=minify(marked(md));// result is now minified html
Reacted by Steven, Mateus Craveiro and Federico Soave
I agree with @UziTech! There are better tools for the job and we should leave this out of marked.
The "dumb" way of implementing this feature would be to just add html-minifier in the bundle. However, this would just add complexity and size to the library.
I would go with adding @UziTech's example to the readme as an "official" solution for the problem.
Activity
jonathanong commentedon Dec 7, 2013
you're not going to gain anything here since it'll just convert
\ncharacters to''.adius commentedon Dec 7, 2013
@jonathanong ? …and why exactly is saving bandwidth and preventing layout bugs because of newline whitespace not an advantage?
jonathanong commentedon Dec 7, 2013
for 100kb of rendered markdown, you're going to save like 50 bytes. it's not about whether there's an advantage or not, it's about cost/benefit.
adius commentedon Dec 7, 2013
and what are the costs? -.- In a cashed environment with heavy traffic it's a huge benefit! (and it's damn annoying if you have to put html code which you normally would split over several lines in the same line to prevent layout bugs, because HTML is NOT whitespace insensitive.
jonathanong commentedon Dec 7, 2013
maintainability. additional options. i doubt you serve enough traffic where the savings would be noticeable - you'd have to be google or Facebook for the benefit to be HUGE. layout bugs with rendered markdown sounds like a CSS problem, which i've never had nor understand since most elements are block elements where whitespace is insignificant.
adius commentedon Dec 7, 2013
This will render a space between the two divs and this is normally not what you want in this situation. To prevent this behavior you have to write them in the same line. This sucks! …but it doesn't look like you are open to any reasonable Arguments. So whatever, I'll just open my own branch. cu
jonathanong commentedon Dec 7, 2013
why would you ever do that? of course you're going to run into layout problems if you write terrible HTML.
actually, more importantly, why would marked do that? but this argument is pointless so i'll stop too.
MasseGuillaume commentedon Aug 21, 2014
@jonathanong I have a good reason for this
I'm using marked inside a pre element since it's space sensitive, the margin dont get merged. I cannot remove newline on the resulting string because code block inside the markdown will loose their layout.
adius commentedon Aug 21, 2014
I had good reasons as well (…and of course I'm not using inline styles in real code)
@jonathanong just seems to be totally unreasonable
Good luck at convincing him of anything.
MasseGuillaume commentedon Aug 22, 2014
@adius ad homminem, the guys is doing a good job with this free open source project.
adius commentedon Aug 22, 2014
maybe. But he's doing a shitty job with this issue…
MasseGuillaume commentedon Aug 25, 2014
@jonathanong
nvm you can use
white-space: normalto discard white spaces in prehowardroark commentedon Sep 16, 2014
I see no reasonable reason to remove the semantic information that whitespace can offer. This is especially true in the case of Markdown where by design you are encouraged to wrap lines. Maybe you wanted to make an editor that could enforce or alter a user's desired line wrap setting. I would also argue that it just makes better sense in terms of search-ability. I think it's a pretty sane choice to leave compression out rather than risk encouraging it.
I would also argue that compression has no real economic value any longer. Cloud keeps getting cheaper and mobile networks keep getting faster. If anything I would say the real enemy is the AMD pattern used in browser based development. It encourages an excess of connections which ultimately slow down a user's experience and adds more traffic.
If you really need to compress, just do it in a post process. I'm sure there has to be something out there to enable that.
rudolfschmidt commentedon Jun 14, 2015
If you compress your regular html it would be nice if the html output from markdown would be also compressed. I agree, its a must have feature. Some workaround already?
1 remaining item
joshbruce commentedon Dec 6, 2017
Was going to mark this as stale, but I'm curious if this is still a desired feature for folks actively using marked.
I see what @jonathanong is saying. I also think there are issues that come with interspersing Markdown and HTML. In some cases, it's better to just pick HTML. Or, compile and inject. With template string literals this could be pretty straightforward. But, I'm new around here still; so, I'll have to use pseudo-code.
If your markdown is coming from a database query, it shouldn't have HTML, in my opinion.
That HTML is definitely strange but, looking at the broader point, knowing what the output is and the possible side-effects of that...anyway....
See #956
adius commentedon Dec 6, 2017
Still desired.
joshbruce commentedon Dec 6, 2017
The drawback I see is the potential cost-benefit of doing something like this. For
<code><pre></pre></code>we need to maintain whitespace. I don't know what the overhead would for stripping whitespace, on the fly, while ignoring the triple-backtick case.adius commentedon Dec 6, 2017
I'd implement the easy solution first. i.e. strip all whitespace between adjacent tags with no content in between.
becomes
This shouldn't break anything and be easy to implement
UziTech commentedon Dec 5, 2018
This can easily be done with other tools after getting the uncompressed output from marked.
mccraveiro commentedon Dec 20, 2018
I agree with @UziTech! There are better tools for the job and we should leave this out of marked.
The "dumb" way of implementing this feature would be to just add
html-minifierin the bundle. However, this would just add complexity and size to the library.I would go with adding @UziTech's example to the readme as an "official" solution for the problem.
UziTech commentedon Dec 20, 2018
I'm going to close this since we will not be adding it to core but will most likely create an extension for it.