The text in my source code is formatted properly, but when it shows up in the browser all the formatting disappears. Is there a tag I could add to the paragraph tag to make the text properly format?
you could use the <pre> and </pre> tags to preserve formatting instead of the <p> tag
The <pre> tag sounds like what you need.
<div style="white-space:pre">
hereIsSomeSourceCode();
if (blah == 3)
doSomething();
</div>
Related
I have a string with some HTML markup, but without any paragraphs. I want to replace newlines with paragraph tags, but if I do it "the dumb way":
html.gsub!(/\s*\n+\s*/, '</p><p>')
html = '<p>' + html + '</p>'
, then I will get markup overlapping:
This is text. <b>Bold text.\n
Still bold,</b> now plain.
becomes:
<p>This is text. <b>Bold text.</p><p>Still bold,</b> now plain.</p>
I know that HTML5 allows overlapping tags, but it is still very-very ugly. I want to get something like this:
<p>This is text. <b>Bold text.</b></p><p><b>Still bold,</b> now plain.</p>
How can I fix this problem?
UPD. <br/> is not what I need - I intend to use Kramdown with custom parser to generate Markdown from this string, and in the string I need open and closing tag for each paragraph.
Insert HTML <br> tags. They are well-defined as standalone tags that don't have paired end tags. If XHTML were still a thing, they would be <br/> tags.
By adding a <br> tag you can insert a single line break. It also has no end tag, so no need to try and close it.
W3Schools - < br > Tag
UPDATED:
If you need paired tags you could create a line break using CSS.
HTML
<p class="break">
Break right after this and
<span>before this</span>
</p>
CSS
p.break {
span {
display: table;
}
}
As shown here on Codepen.
Right now I have posted the code into a textbox because I want the code in plain text. Now I wonder if I can put the code into a div box instead i get the same result.
Right now:
<textarea id="copytext" readonly="readonly"><p>Show the p tags in plain text</p></textarea>
Place your code between <pre> tags so that it is not interpreted by your browser. http://www.w3schools.com/tags/tag_pre.asp
<pre><img src="pic.jpg"></pre>
if you want a block of code this should be your markup:
<blockquote>
<pre>
<code>
My pre-formatted "quoted" code here.
</code>
</pre>
</blockquote>
Also take a look at this tool: https://code.google.com/p/syntaxhighlighter/
Testing 123, This shows the picture for me ????
<blockquote>
<pre>
<code>
<img src="http://lorempixel.com/200/200"/>
</code>
</pre>
</blockquote>
im looking for a way to show html as html without the browser reading it,
i found <plainttext> but once i start it i can't stop it
for example:
<plaintext>
<span> dobeediedabiedadadee olleeeeee</span>
</plaintext>
<h1>hi</h1>
in this example the span had to be shown as text and the h1 as a header, but the output is:
<span> dobeediedabiedadadee olleeeeee</span>
</plaintext>
<h1>hi</h1>
</body>
</html>
here a JSFiddle link:
JSFiddle
a other solution as plaintext is also welcome
thanks for your time.
plaintext has long been deprecated, just use > and <
<span> dobeediedabiedadadee olleeeeee</span>
DEMO: Fiddle
You could always use javascript to escape the HTML. Here is a fiddle.
html.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
The following link describes the difficulty in using <plaintext>. long story short it is not fully supported in any browser and you should be using <pre> instead.
http://reference.sitepoint.com/html/plaintext
<plaintext> is not a pair tag. From that tag to the rest of the page, everything is interpreted as text. However, this is not standard and obsolette in HTML5:
Examples
No, really. don't use it.
It is literally written in the w3 reference
Use PRE
<pre>
<span> dobeediedabiedadadee olleeeeee</span>
</pre>
<h1>hi</h1>
it is compatibility issue some browser completely ignores coding of
have a look at this link http://reference.sitepoint.com/html/plaintext
i would suggest you use instead
So i'm trying to assign a hyperlink to a single word in a {p} tag in an .aspx page in MS expressions.
My problem:
when i try to do this:
<p>Some text with a HYPERLINK then there's more text here like this</p>
it shows up in the browser as such:
some text with a
HYPERLINK
then there's more text here like this
I'm trying to get it all on one line like it should be.. any ideas??
My best guess, is that your anchor tag is styled as display : block, can you confirm this by using inspect element, or providing a link to where this bug is occurring?
Use Nobr html tag. Anything in between will not be broken in multiple lines.
<nobr>My long sentence</nobr>
<nobr> tag is deprecated.
One can use : white-space : nowrap ;
<a style = " white-space:nowrap; " href="******">HYPERLINK</a>
I need to include some codes in my html document
I've tried <pre> tag, but that didn't help.
How do I get this code into a document like text?
Thanks
Short Answer.
Encode your code using an online HTML Encoder and then put it inside pre
<pre>
<%--your encoded code goes here--%>
</pre>
Long Answer.
The above will only help you to show your code. If you want proper highlighting for your code, Try something like SyntaxHighlighter
Link: How to use SyntaxHighlighter.
You have to use html entities. Example:
<div>
Some Stuff
</div>
should be
<div>
Some Stuff
</div>
and it will render as the first one
You can use <pre> tag. Each time you insert any texts within the <pre> tag it wont get parsed as html document. One caveat though, if you try to put an opening HTML tag inside the pre tag, you have to do it like this:
<pre>
<TEST>
TEST!!
</TEST>
</pre>
Use the xmp tag. It is easier and quicker than using an HTML encoder. Example:
<h1>This is a heading.</h1>
<p>This is a pharagraph</p>
<xmp>
<h1>This is a heading.</h1>
<p>This is a pharagraph</p>
</xmp>
You can use a combination of the <pre> and <code> tags. The <pre> tag retains the formatting , and the <code> tag outputs in monospaced font. Wrap the <code> tag in <pre> tag, and paste whatever block of code in the <code> elements body. This will output like the following:
<pre>
<code>
function(){
var myVar = "This is code";
return myVar;
}
</code>
</pre>
Some people might crucify me not escaping my code. But this worked for me.
CSS
.tag:before{
content: '<'
}
.tag:after{
content: '>'
}
HTML
<pre>
<span class="tag">tag</span>
</pre>
<!--Instead of having to escaping all the character-->
<tag> </tag>
<!--Kinda interested to see why this is bad. I understand that not escaping code can be dangerous b/c of SQL injections and all sort of BS but why is this not a viable option-->
Use
encode
Example:
<br> -> encoded -> <br>
use <br> in your text
same answer as Ibu but maybe you want a fast way to encode your tags.
To not escape any characters at all, you can use a textarea:
textarea {
font-family: inherit;
font-size: inherit;
border: none;
background-color: transparent;
resize: none;
outline: none;
}
<div>In order to show a bullet point in html use the li tags:</div>
<div>
<textarea readonly><li>Hello</li></textarea>
</div>
<div>And this is what it will look like:</div>
<li>Hello</li>
Run the snippet and notice the <li> and </li> tags render verbatim rather than being converted to a bullet.
Now why do we need the CSS and the extra HTML tags and attributes?
The CSS removes all the styling from textarea since the textarea will typically include styling for borders, resize gripper, and will use "input" style fonts. The textarea tag needs the "readonly" attribute so users can't edit it. The extra div tag around the textarea makes the textarea insert more correctly into the document flow.
It has some extra steps and it changes the DOM considerably but if you really need to show text strictly without escaping any characters at all for whatever reason.
I guess you just want to display a piece of code so you can just use https://highlightjs.org/
include this in your web page:
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release#11.6.0/build/styles/default.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release#11.6.0/build/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
then add the <pre><code> tags to wrap your escaped piece of code
you can use https://www.freeformatter.com/html-escape.html
<pre>
<code class="language-html">
<h1>this is my HTML code</h1>
</code>
</pre>
or for CSS code
<pre>
<code class="language-css">
input { caret-color: red;}
</code>
</pre>
doc here https://highlightjs.org/usage/