I have the following template
{{#if:{{{1|}}}|{{Subtemplate|{{{1}}}}}}}
{{#if:{{{2|}}}|{{Subtemplate|{{{2}}}}}}}
{{#if:{{{3|}}}|{{Subtemplate|{{{3}}}}}}}
{{#if:{{{4|}}}|{{Subtemplate|{{{4}}}}}}}
{{#if:{{{5|}}}|{{Subtemplate|{{{5}}}}}}}
{{#if:{{{6|}}}|{{Subtemplate|{{{6}}}}}}}
{{#if:{{{7|}}}|{{Subtemplate|{{{7}}}}}}}
{{#if:{{{8|}}}|{{Subtemplate|{{{8}}}}}}}
{{#if:{{{9|}}}|{{Subtemplate|{{{9}}}}}}}
{{#if:{{{10|}}}|{{Subtemplate|{{{10}}}}}}}
{{#if:{{{11|}}}|{{Subtemplate|{{{11}}}}}}}
{{#if:{{{12|}}}|{{Subtemplate|{{{12}}}}}}}
and it works perfectly well to be used as {{Template|first|second|third}} but it keeps printing empty paragraphs for the parameters that are not present. How can I get rid of them?
Try removing the newlines between if-statements:
{{#if:{{{1|}}}|{{Subtemplate|{{{1}}}}}}}<!--
-->{{#if:{{{2|}}}|{{Subtemplate|{{{2}}}}}}}<!--
-->{{#if:{{{3|}}}|{{Subtemplate|{{{3}}}}}}}<!--
-->{{#if:{{{4|}}}|{{Subtemplate|{{{4}}}}}}}<!--
-->{{#if:{{{5|}}}|{{Subtemplate|{{{5}}}}}}}<!--
-->{{#if:{{{6|}}}|{{Subtemplate|{{{6}}}}}}}<!--
-->{{#if:{{{7|}}}|{{Subtemplate|{{{7}}}}}}}<!--
-->{{#if:{{{8|}}}|{{Subtemplate|{{{8}}}}}}}<!--
-->{{#if:{{{9|}}}|{{Subtemplate|{{{9}}}}}}}<!--
-->{{#if:{{{10|}}}|{{Subtemplate|{{{10}}}}}}}<!--
-->{{#if:{{{11|}}}|{{Subtemplate|{{{11}}}}}}}<!--
-->{{#if:{{{12|}}}|{{Subtemplate|{{{12}}}}}}}
Related
I'm using Prototype's PeriodicalUpdater to update a div with the results of an ajax call. As I understand it, the div is updated by setting its innerHTML.
The div is wrapped in a <pre> tag. In Firefox, the <pre> formatting works as expected, but in IE, the text all ends up on one line.
Here's some sample code found here which illustrates the problem. In Firefox, abc is on different line than def; in IE it's on the same line.
<html>
<head>
<title>IE preformatted text sucks</title>
</head>
<body>
<pre id="test">
a b c
d e f
</pre>
<script type="text/javascript"><!--
var textContent = document.getElementById("test").innerText;
textContent = textContent.replace("a", "<span style=\"color:red;\">a</span>");
document.getElementById("test").style.whiteSpace = "pre";
document.getElementById("test").innerHTML = textContent;
--></script>
</body>
</html>
Anyone know of a way to get around this problem?
Setting innerHTML fires up an HTML parser, which ignores excess whitespace including hard returns. If you change your method to include the <pre> tag in the string, it works fine because the HTML parser retains the hard returns.
You can see this in action by doing a View Generated Source after you run your sample page:
<PRE id="test" style="WHITE-SPACE: pre"><SPAN style="COLOR: red">a</SPAN> b c d e f </PRE>
You can see here that the hard return is no longer part of the content of the <pre> tag.
Generally, you'll get more consistent results by using DOM methods to construct dynamic content, especially when you care about subtle things like normalization of whitespace. However, if you're set on using innerHTML for this, there is an IE workaround, which is to use the outerHTML attribute, and include the enclosing tags.
if(test.outerHTML)
test.outerHTML = '<pre id="test">'+textContent+'</pre>';
else
test.innerHTML = textContent;
This workaround and more discussion can be found here: Inserting a newline into a pre tag (IE, Javascript)
or you could
if (el.innerText) {
el.innerText = val;
} else {
el.innerHTML = val;
}
Don't know if this has been suggested before, but the solution I found for preserving white space, newlines, etc when doing an innerHTML into a 'pre' tag is to insert another 'pre' tag into the text:
<pre id="pretag"></pre>
TextToInsert = "lots of text with spaces and newlines";
document.getElementById("pretag").innerHTML = "<pre>" + TextToInsert + "</pre>";
Seems I.E. does parse the text before doing the innerHTML. The above causes the parser to leave the text inside the additional 'pre' tag unparsed. Makes sense since that's what the parser is supposed to do. also works with FF.
It could also be rewritten 'the Python way', i.e.:
el.innerText && el.innerText = val || el.innerHTML = val;
I have wrote that script that uses yandex api to convert some foreign characters in english, here is the code:
for pre in soup.select('body'):
pree= pre.text
print (pree)
HTML is:
<body>
onComplete_10([{"Alignment":"0:1-0:4 2:2-6:9 3:3-6:9","From":"zh-CHS","OriginalTextSentenceLengths":[4],"TranslatedText":"Drama Arts","TranslatedTextSentenceLengths":[10]}]);
</body>
Returned result is(of course):
onComplete_10([{"Alignment":"0:1-0:4 2:2-6:9 3:3-6:9","From":"zh-CHS","OriginalTextSentenceLengths":[4],"TranslatedText":"Drama Arts","TranslatedTextSentenceLengths":[10]}]);
I need to get only translated text which is "Drama Arts".
NOTE:
I have updated my for loop. Now using regex to filter my required data but still no luck.
for pre in soup.select('body'):
p = re.compile(ur'"TranslatedText":"(.*?)"')
strr = pre.text
pree = re.findall(p, strr)
print (pree)
Just changed it a bit was doing a slight mistake. Though for some reason above works with regex101.
for pre in soup.select('body'):
p = re.compile(u'"TranslatedText":"(.*?)"')
strr = pre.text
pree = re.findall(p, strr)
print (pree)
So, I am trying to get a date out of html using VBA in Excel, and I am having issues finding a way to extract the text that I want it appears as:
<SPAN id=ctl00_ContentPlaceHolder1_lblDateCreated2>5/22/2012 8:14:08 PM</SPAN>
I want extract the 5/22/2012 8:14:08, but as it is not a string and in between the carats, I don't know exactly how to do it. Any tips?
I figured out that I was using ".innerText" incorrectly, and I was able to get it working with the following snippet.
Doc.getElementById("ctl00_ContentPlaceHolder1_lblDateCreated2").innerText
You could do this in VBA with split:
theString = "<SPAN id=ctl00_ContentPlaceHolder1_lblDateCreated2>5/22/2012 8:14:08 PM</SPAN>"
Temp = Split(theString, "ContentPlaceHolder1_lblDateCreated2>")(1)
Final = Split(Temp, "</")(0)
The first Split will return an array of two parts:
Temp(0) = "<SPAN id=ctl00_"
Temp(1) = "5/22/2012 8:14:08 PM</SPAN>"
Next we Split Temp(1) to remove the closing SPAN tag and return just the date and time.
I think you're just looking for a Mid() formula. If that URL/Span part in A1, put this in A2 (or wherever):
=MID(A1,SEARCH(">",A1)+1,FIND("</",A1)-FIND(">",A1)-1)
I want to add a newline in a textarea. I tried with \n and <br/> tag but are not working. You can see above the HTML code. Can you help me to insert a newline in a textarea?
<textarea cols='60' rows='8'>This is my statement one.\n This is my statement2</textarea>
<textarea cols='60' rows='8'>This is my statement one.<br/> This is my statement2</textarea>
Try this one:
<textarea cols='60' rows='8'>This is my statement one.
This is my statement2</textarea>
Line Feed and
Carriage Return are HTML entitieswikipedia. This way you are actually parsing the new line ("\n") rather than displaying it as text.
Break enter Keyword line in Textarea using CSS:
white-space: pre-wrap;
I think you are confusing the syntax of different languages.
is (the HtmlEncoded value of ASCII 10 or) the linefeed character literal in a HTML string. But the line feed character does NOT render as a line break in HTML (see notes at bottom).
\n is the linefeed character literal (ASCII 10) in a Javascript string.
<br/> is a line break in HTML. Many other elements, eg <p>, <div>, etc also render line breaks unless overridden with some styles.
Hopefully the following illustration will make it clearer:
T.innerText = "Position of LF: " + t.value.indexOf("\n");
p1.innerHTML = t.value;
p2.innerHTML = t.value.replace("\n", "<br/>");
p3.innerText = t.value.replace("\n", "<br/>");
<textarea id="t">Line 1
Line 2</textarea>
<p id='T'></p>
<p id='p1'></p>
<p id='p2'></p>
<p id='p3'></p>
A few points to note about Html:
The innerHTML value of the TEXTAREA element does not render Html. Try the following: <textarea>A <a href='x'>link</a>.</textarea> to see.
The P element renders all contiguous white spaces (including new lines) as one space.
The LF character does not render to a new line or line break in HTML.
The TEXTAREA renders LF as a new line inside the text area box.
I've found String.fromCharCode(13, 10) helpful when using view engines.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
This creates a string with the actual newline characters in it and so forces the view engine to output a newline rather than an escaped version. Eg: Using NodeJS EJS view engine - This is a simple example in which any \n should be replaced:
viewHelper.js
exports.replaceNewline = function(input) {
var newline = String.fromCharCode(13, 10);
return input.replaceAll('\\n', newline);
}
EJS
<textarea><%- viewHelper.replaceNewline("Blah\nblah\nblah") %></textarea>
Renders
<textarea>Blah
blah
blah</textarea>
replaceAll:
String.prototype.replaceAll = function (find, replace) {
var result = this;
do {
var split = result.split(find);
result = split.join(replace);
} while (split.length > 1);
return result;
};
<textarea cols='60' rows='8'>This is my statement one.
This is my statement2</textarea>
Fiddle showing that it works: http://jsfiddle.net/trott/5vu28/.
If you really want this to be on a single line in the source file, you could insert the HTML character references for a line feed and a carriage return as shown in the answer from #Bakudan:
<textarea cols='60' rows='8'>This is my statement one.
This is my statement2</textarea>
Try this. It works:
<textarea id="test" cols='60' rows='8'>This is my statement one.
This is my statement2</textarea>
Replacing for <br> tags:
$("textarea#test").val(replace($("textarea#test").val(), "<br>", "
")));
To get a new line inside text-area, put an actual line-break there:
<textarea cols='60' rows='8'>This is my statement one.
This is my statement2</textarea>
You might want to use \n instead of /n.
After lots of tests, following code works for me in Typescreipt
export function ReplaceNewline(input: string) {
var newline = String.fromCharCode(13, 10);
return ReplaceAll(input, "<br>", newline.toString());
}
export function ReplaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
You should also check the css white-space property (mdn docs) of your element, make sure it's set to a value that doesn't suppress line breaks, e.g.:
white-space: pre-line;
You'd be interested in these 3 values:
pre
Sequences of white space are preserved. Lines are only broken at
newline characters in the source and at <br> elements.
pre-wrap
Sequences of white space are preserved. Lines are broken at
newline characters, at <br>, and as necessary to fill line boxes.
pre-line Sequences of white space are collapsed. Lines are broken at
newline characters, at <br>, and as necessary to fill line boxes.
My .replace()function using the patterns described on the other answers did not work. The pattern that worked for my case was:
var str = "Test\n\n\Test\n\Test";
str.replace(/\r\n|\r|\n/g,'
');
// str: "Test
Test
Test"
T.innerText = "Position of LF: " + t.value.indexOf("\n");
p3.innerText = t.value.replace("\n", "");
<textarea id="t">Line 1
Line 2</textarea>
<p id='p3'></p>
If you are using react
Inside the function
const handleChange=(e)=>{
const name = e.target.name;
let value = e.target.value;
value = value.split('\n').map(str => <span>{str}<br/></span>);
SetFileds({ ...fileds, [name]: value });
}
A simple and natural solution not involving CSS styles or numeric character references like
would be to use the 
 character entity reference:
The cardinal directions are:
- North
- East
- South
- West
Note: Since this is defined simply as the LF (line feed, or the U+000A Unicode code point) character, it's not 100% certain whether it suits situations where the entire CR + LF (carriage return + line feed) sequence is required. But then, it worked in my Chrome, Edge and WebView2 tests done on Windows 10, so it should be ok to use.
just use <br>
ex:
<textarea>
blablablabla <br> kakakakakak <br> fafafafafaf
</textarea>
result:
blablablabla kakakakakak fafafafafaf
Is there a way to remove an entire row (html tags 'n all) from an HTML Table with HTML::TableExtract?
Mucking around with the sample code from CPAN, this is what I've tried so far:
use HTML::TableExtract qw(tree);
my $te = HTML::TableExtract->new( headers => [qw(name type members)] );
# get $html_string out of a file...
$te->parse($html_string);
my $table = $te->first_table_found();
my $table_tree = $table->tree;
$table_tree->row(4)->replace_content('');
my $document_tree = $te->tree;
my $document_html = $document_tree->as_HTML;
# write $document_html to a file ...
Now, as the name suggests, 'replace_content()' in the line $table_tree->row(4)->replace_content(''); removes the content of row 4, but the row itself remains in markup. I need to get the tags and everything in-between removed as well.
Any ideas?
What you want is the parent and delete methods
See the docs for HTML::Element and for HTML::Element::delete
UPDATE
Ok, click that checkmark and mark this one as answered....Here it is:
my($p) = $table_tree->row(4)->parent();
$p->delete;
Also, NOTE, you need the () parens around $p! If you don't have parens don't get back a reference.
For me, with the above Perl code working on this HTML,
<table>
<tr><td>name</td><td>type</td><td>members</td></tr>
<tr><td>row1</td><td>row1</td> <td>row1</td></tr>
<tr><td>row2</td><td>row2</td> <td>row2</td></tr>
<tr><td>row3</td><td>row3</td> <td>row3</td></tr>
<tr><td>row4</td><td>row4</td> <td>row4</td></tr>
</table>
I get this as a result of printing $document_html
<table>
<tr><td>name</td><td>type</td><td>members</td></tr>
<tr><td>row1</td><td>row1</td><td>row1</td></tr>
<tr><td>row2</td><td>row2</td><td>row2</td></tr>
<tr><td>row3</td><td>row3</td><td>row3</td></tr>
</table>
Notice that there is no empty <tr></tr>