I have a string that will be mixed with text and html markup that I would like to parse and deal with accordingly. The HTML markup with include references to record ID's that I can use later when compiling text and mention segments for a post.
For the most part, I'm understanding how to split out the individual segments, but I don't know how to get them back in the correct order in which they came.
An example string:
Hi <span contenteditable="false" data-mention="#005i0000003KteOAAS">First Name</span>
I can parse into 'Hi ' and '005i0000003KteOAAS' individually, but how do I get them back in the original order?
I'm using a regex like this currently:
<(?i).*?<\\/.*?>
Related
I am using react table. I am calling a method on API (.NET), which concatenates some fields and now I need to display this concatenated field in react table column.
From API I tried to put /n in the column so that it renders a new line on UI (inside react table). But no luck. Example: I need to display
This field is calculated by adding two numbers 10 and 20. Since the
result is greater than 15 you cannot perform this operation.
In the displayed text, what I want is "Since" should start in a new line in react table.
I tried to put {'\n'} before "Since" but it did not work. Any ideas how to achieve this?
The '\n' escape character does not work in HTML. You have to work with
other HTML solutions like using <br> or divs to get a multiline
implementation working.
You solve this quite easily. when getting the string append a special char like the comma (,) or some other char that you are sure would not be used in your original text.
Then get that string to a js variable in your react app.
let multiLineString = "This field is calculated by adding two numbers 10 and 20. , Since the result is greater than 15 you cannot perform this operation";
let lines = multiLineString.split(',')
let linesHTML = lines.map((line)=><div>{line}</div>);
now render this variable anywhere you want, you will get a multi line string implementation.
Of course the better approach would be to get a json array of values from the back end.
In ColdFusion I am creating and saving a file, then later looping over characters in the file to display part of it. This is almost working, but the loop is sometimes inserting characters that are formatting rather than just the output. And sometimes it is losing the formatting. Here are the original and the version as read:
The code:
<cfset colvalue = getPageContext().getRequest().getParameterValues('#col#')>
<cfset repa = colvalue[1]>
<cfloop file="#reppath#moxrep/#repa#.cfm" index="chunk" characters="500">
<cfoutput>#chunk#</cfoutput><br>
</cfloop>
Am I doing something wrong in the code? Is there a bug in the ColdFusion loop over file? And if so, is there a workaround?
<cfloop .. characters="500">
It is because your loop uses the "characters" attribute, which limits the number of characters "..read during each iteration of the loop..". That would be fine for a text file. However, since the file content is HTML, it breaks when you try and insert the <br> at an arbitrary position. That causes part of the HTML code to be displayed instead of rendered. For example:
<div <br> style="text-align: left; ">This will not render correctly</div>
That said, it begs the question why read the content line by line instead of just displaying the whole file?
Update:
You really cannot parse HTML with basic string functions or regular expressions - not with any reliability. Encountering a new line character does not necessarily mean you have reached the end of a particular block of HTML code. It is perfectly valid for an HTML element to span multiple lines. Plus, HTML elements are frequently nested. So it is near impossible to identify the "logical" endpoints using string functions (which is basically what the cfloop is doing) alone.
Instead, I would recommend using a tool like JSOUP which is specifically designed for parsing HTML. Once you have parsed the document, it is very easy to access specific elements or sections of the HTML.
I've got a button with the following ID
<button id="Emp Btn"....
I'm unable to access it because of the space
I've tried the following and they don't work
element(by.id("Emp Btn"));
element(by.id("Emp%20Btn"));
element(by.id("Emp%Btn"));
element(by.id('Emp Btn'));
its bad idea to use spaces in ID. HTML 5 says, that an id must contain at least one character and must not contain space characters.
But you still can find such element using XPath.
Try to use something like this:
.\\button[contains(#id,'firstPart') and contains(#id,'secondPart')]
In my application I have Terms for Apps. Before I used to put this in front-end with HTML .
But now I need to put this text in database in a column called AppTerms inside table called App.
I referred to this link in stackoverflow and followed like this :
UPDATE [AppsDatabase].[dbo].[App]
SET AppTerms = 'This App has no minimum term.' + CHAR(13) +
'This App is built and is supported through the standard way of using the company online support.' + CHAR(13) +
'Incorrectly formatted data will not be formatted but may be charged for.'
WHERE AppID = 8
GO
But I am not getting line breaks here. And also can someone tell me how can i put bullet points in each line?
If you are showing HTML you need to store </br> instead of CHAR(13).
Displaying this text in HTML will yield the correct display. In addition you can wrap a paragraph in <p>...</p>.
For bullet lists look at http://www2.gol.com/users/billp/articlehtml/bullet.html.
This is under the assumption that you take the text out and display in HTML.
It might be too late, yet, I had the same problem...
The solution I came up with is to store paragraphs(or lists... or whatever) in a separate child table and handle the formatting at the server programming language level.
It should work. In HTML you could use the </br> tag.
You want the application to render HTML with line breaks, but you're storing plain text.
You need to store HTML instead. Encode the line breaks using the <br> element.
Try this:
UPDATE [AppsDatabase].[dbo].[App]
SET AppTerms = 'This App has no minimum term.<br>' + CHAR(13) +
'This App is built and is supported through the standard way of using the company online support.<br>' + CHAR(13) +
'Incorrectly formatted data will not be formatted but may be charged for.'
WHERE AppID = 8;
If you want to encode bullet points, check out the <ul> and <li> elements.
This is a data formatting issue more than a SQL Server issue. You would have had the same problem if you tried to store the data in a file instead of a table.
The W3C specification for HTML Text explains how white space is handled in HTML:
In HTML, only the following characters are defined as white space
characters:
ASCII space ( )
ASCII tab ( )
ASCII form feed ()
Zero-width space ()
Line breaks are also white space characters.
[...] user agents should collapse input white space sequences when producing output inter-word space.
Line breaks are equivalent to spaces, and multiple white space characters are collapsed to a single space in the output.
extJS didnt see too big text with many <\br>'s..
If i write text something like "lalal lalalal lsadsdhas afjhjhj";
Its okei, works.
If i write text with \n (<\br>) something like:
"hello,
my name
is Polly!";
ExtJS didnt see those lines. How i can avoid this?
Thank you!
This is because Javascript doesn't allow multi-line strings. If you want a linebreak in your string, it has to be coded with an escape sequence like '\r\n'. So,
alert("hello, \r\nmy name\r\nis Polly!");
will display as 3 lines. If the string is going into an html element, then insert '<br />' in place of the '\r\n'.
finally, if you need a long string with lots of blank spaces between the words, for some reason, you can either keep typing on the same line, or break it up into several lines and combine the lines with the '+' operator, like this:
var longstring =
'hello \r\n'
+'my name \r\n'
+'is Polly!';