I am a very beginner in Pug and I'm trying to solve the following task: Every occurrence (in text) of the following words shall become a link to the destination defined below:
sed -> https://google.com
liq -> https://facebook.com
Тhis works as I expected, but keeps anchor tag as string.
- var str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar elementum integer sed neque volutpat ac. Facilisis liq odio morbi quis commodo odio aenean . Vel facilisis volutpat liq velit. Viverra aliquet liq sit amet tellus cras adipiscing sed.";
- var url = '#[a(href="https://google.com") sed]'; //I tried with these ones too - var url = 'sed'; var url = 'a(href="https://google.com)sed'
- var res = str.replace(/sed/g, url);
p #{res}
Here my latest atempt:
mixin link(href, name)
a(href=href target!=attributes.target )= name
//+link('https://google.com', 'Google')(target="blank")
- var str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar elementum integer sed neque volutpat ac. Facilisis liq odio morbi quis commodo odio aenean . Vel facilisis volutpat liq velit. Viverra aliquet liq sit amet tellus cras adipiscing sed.";
- var link = +link('https://google.com', 'Google')(target="blank");
- var res = str.replace(/sed/g, link);
p #{res}
I've never seen Pug mixins used within javascript code blocks like that before. I'm surprised it even outputs the anchor tag at all.
That being said, you can use the unescaped string interpolation syntax (!{variable}) instead of the regular string interpolation syntax (#{variable}) to get the link to render as a link.
In your case:
p !{res}
But keep in mind this word of warning from the Pug documentation:
Caution
Keep in mind that buffering unescaped content into your templates can be mighty risky if that content comes fresh from your users. Never trust user input!
Related
I cannot get the MS recommended 'work-around' for COUNTIF/COUNTIFS criteria greater than 255 characters to produce any result beyond a worksheet #VALUE! error.
Source: COUNTIF function
Wrong value returned The COUNTIF function returns incorrect results when you use it to match stringsfor long strings longer than 255 characters. To match strings longer than 255 characters, use the CONCATENATE function or the concatenate operator &. For example, =COUNTIF(A2:A5,"long string"&"another long string")
Sample text string with a 504 character length string in A2:A5,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur et mi congue, ullamcorper, nulla non, interdum augue. Etiam at turpis sagittis, auctor ante quis, imperdiet neque. Nulla ut mauris ac enim rutrum congue. Vivamus elementum nisi et lectus scelerisque bibendum. Mauris tristique condimentum purus, dictum sagittis velit. Cras non purus ut magna placerat suscipit nec sit amet est. Nam finibus sed nibh ac euismod. Nam fermentum mattis quam, a commodo elit suscipit nec. In eu ipsum iaculis.
Formula per support.office.com recommendations,
'this exceeds 255 character limit
=countif(a:a, a2)
'this is the recommended work-around
=countif(a:a, left(a2, 255)&mid(a2, 256, 255))
'alternate for a2 < 256 characters
=countif(a:a, left(a2, 255)&iferror(mid(a2, 256, 255), text(,)))
Result should be 4. I cannot get anything but #VALUE! if A2 contains any text with a length longer than 255.
Hard-coding the first 255 characters suffixed with the second remaining 249 characters does nothing but return the same #VALUE! error.
=COUNTIF(A:A, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur et mi congue, ullamcorper, nulla non, interdum augue. Etiam at turpis sagittis, auctor ante quis, imperdiet neque. Nulla ut mauris ac enim rutrum congue. Vivamus elementum nisi et lectus s"&"celerisque bibendum. Mauris tristique condimentum purus, dictum sagittis velit. Cras non purus ut magna placerat suscipit nec sit amet est. Nam finibus sed nibh ac euismod. Nam fermentum mattis quam, a commodo elit suscipit nec. In eu ipsum iaculis.")
I guess you want a question. Does this work at all? What am I missing? Is it my xl2010/xl2016 versions? The documentation I've referred to seems current.
Addendum:
If this does not work as described (or even as imagined) then a proof of a broken concept is easily an acceptable answer.
This will do strings up to 508 character fairly reliably.
=COUNTIFS(D1:D5,LEFT(D1,254)&"*",D1:D5,"*" &RIGHT(D1,254))
It will, in fact, do larger strings by comparing the last 254 and the first 254. Which may or may not suffice for individual requirements.
But may give false positives if the search parameters are shorter than 255 and, the to be searched ends and begins with the same text. For example test test will be counted twice if A1 is test.
This question already has answers here:
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 6 years ago.
This post was edited and submitted for review 15 days ago.
I want to remove every html tag with awk from this regex: /[<.*.>]/ if said regex is found in any field. I've been trying to make it work with sub or substr, I am unable to find the correct logic for this.
Input text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation<br/><div style="margin-top:6px">< b>veniam:< /b>< /div> <br/><div style="margin-top:6px">< b>Confort:< /b></div>Comenzi volan; Cruise-control; Servodirectie; <br/>
Output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitationveniam: Confort:Comenzi volan; Cruise-control; Servodirectie;
If you're not really parsing HTML but instead just want to remove everything between each <...> pair in a text file, then that'd be this with GNU awk for multi-char RS:
$ awk -v RS='<[^>]+>' -v ORS= '1' file
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitationveniam: Confort:Comenzi volan; Cruise-control; Servodirectie;
When writing a long footnote with LilyPond 2.17.25, the text is not breaking into several lines or respecting the margin limits. I would love to have it set to justified alignment as well, if that is possible.
Here is a tiny example:
\version "2.17.25"
{
\footnote #'(-1 . 1)
\markup{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget ante venenatis mi consectetur ornare. Cras facilisis dictum venenatis. Donec.}
a'4 b' c'' d''
}
Thanks a lot!
The solution is to simply add \justify or \wordwrap to the \markup command, as:
\version "2.17.25"
{
\footnote #'(-1 . 1)
\markup\justify{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget ante venenatis mi consectetur ornare. Cras facilisis dictum venenatis. Donec.}
a'4 b' c'' d''
}
I am trying to write a script that gets input from a user and returns the input in a formatted area. I have been using the string range function however it obviously cuts the the input at the range that I give. Is there any way to do a look around at the specified range to find the next space character and cut the input at that location?
For example, if I have the input of:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
My current string range function formats the input with \r\n as such:
Lorem ipsum dolor sit amet, consectetur a
dipisicing elit, sed do eiusmod tempor in
cididunt ut labore et dolore magna aliqua
. Ut enim ad minim veniam, quis nostrud e
xercitation ullamco laboris
As you can see on line 1 the adipisicing line 2 incididunt words have been cut off. I am looking for a way to look for the closest space to that location. So for line 1 it would have been before the a on line 2 it would have been before the i. …In some cases it may be after the word.
Is that clear what I am looking for? Any assistance would be great!
The string range operation is pretty stupid; it doesn't know anything about the string it is splitting other than that it contains characters. To get smarter splitting, your best bet is probably an intelligently chosen regular expression:
set s "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\
nostrud exercitation ullamco laboris."
# Up to 40 characters, from word-start, to word-start or end-of-string
set RE {\m.{1,40}(?:\m|\Z)}
# Extract the split-up list of "lines" and print them as lines
puts [join [regexp -all -inline $RE $s] "\n"]
This produces this output for me:
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris.
Implementing full justification by inserting spaces is left as an exercise for the reader (because it's really quite a lot harder than greedy line splitting!)
The textutil::adjust module in tcllib is what you need:
package require textutil::adjust
set line "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris"
set formatted [textutil::adjust::adjust $line -length 41]
puts $formatted
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris
For the life of me, I cannot figure out the cause of this: when writing in LaTeX documents, I like to keep my line width to maximum of 80 characters. As such, I will execute the vim command gqap and vim will automatically re-wordwrap the paragraph I am writing.
For example, it will cause a long line to become many shorter ones:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem. Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec, vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam tincidunt. Proin condimentum rutrum lacinia.
becomes:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec,
vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam
tincidunt. Proin condimentum rutrum lacini
But, for some paragraphs, it will start adding unusual indentions towards the end of the paragraph:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla,
vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula
tincidunt. Proin condimentum rutrum lacini
Why does vim do this? I have yet to figure out the pattern. How can I make it format paragraphs "the correct way"?
Yes, vim's 'smartindent' is not well named. I had trouble with this for a while before I figured out what was wrong. For others, if you notice strange indenting behavior after lines starting with "if" or "for", unset smartindent. You will come across this a lot if you start using vim as a word processor.
From the vim help file, 'smartindent' will indent after a line starting with a keyword from 'cinwords', which is "if,else,while,do,for,switch", by default.
The problem was that I had "smartindent" enabled. Disabling this for LaTeX documents solved it:
au BufEnter *.tex set nosmartindent