PhpStorm/WebStorm: how to parse selected text with php script? - html

There are Live Templates, there is Emmet as well but I can't get with them what I need.
I want to change selected text like for example this:
About Us
Contact Us
Some other page
into:
<ul>
<li>About Us<li>
<li>Contact Us<li>
<li>Some other page<li>
</ul>
And it would be best if I could do that with a shortcut key.
I used that a lot in PHPEd By Nusphere but here I don't see such an option.
There was there option: get selection, parse with PHP script via shell and output back to editor and that way I could do anything with selected text.
Is that possible with PhpStorm?
Is there something that I could use to achieve this effect with just one click?
I can do a Live template for one line of text, I don't see possibility to cover more lines at once. Then I could at least get just list of <li>s without <ul>.

Related

Add html elements and json list inside angular typescript class

I have this code.
this._notificationService.showInfoMessage
(
'The list below cannot be reached'
+ `'<ul>
<li> ${this.tagList
.map(i => i.tag)
.join(',')} </li>
</ul>'`
);
It does not work
I want add html list inside component.ts file for this tag list and show list items one by one as a list with bullets.
I have tried many ways.
I made it using browser inspect view
I want to get as below one
please suggest best way for this
Why it doesn't work?
Just check what says the official Angular documentation.
Angular recognizes the value as unsafe and automatically sanitizes it,
which removes the script element but keeps safe content such as the
element.
https://angular.io/guide/security#sanitization-example
That is how it's working!
But still, you have many options to achieve your goal.
Since you have a list/array of tags you could just iterate over them in the template and use string interpolation.
<ul>
<li *ngFor="let tag of tags">{{tag}}</li>
</ul>
Text interpolation:
https://angular.io/guide/interpolation
P.S Please, share with us what your service/component looks like.

Move cursor via Xpath

Within the Ace editor HTML panel is it possible to move the cursor if I know the Xpath of the dom element?
For instance if I have this path
/html/body/nav/ul/li[2]
I would love to be able to move the cursor to
<html>
<body>
<nav>
<ul>
<li>Alpha</li>
*here*<li>Beta</li>
<li>Gama</li>
</ul>
</nav>
</body>
</html>
I guess one option is to write a regex based on opening tags but maybe there was a cleaner way. Haven't been able to see from the API if it's possible.,
Turns out I was over thinking the problem. I reinterpreted the path
/html/body/nav/ul/li[2]
to
/html/body/nav/ul/li/li
Split those and then had the Ace editor do a sequential find from the beginning. So find "<html" and then "<body" and then "<nav" etc.

linebreaks filter with mixed HTML \ plain text string

I have a string like this:
Plain text with newlines.
But it also has some html.
<ul>
<li>first</li>
<li>second</li>
</ul>
I'd like the lineabreaks filter to output an HTML like this:
<p>Plain text with newlines.<br/>
But it also has some html.</p>
<ul>
<li>first</li>
<li>second</li>
</ul>
But what I get is:
<p>Plain text with newlines.<br/>
But it also has some html.</p>
<ul><br />
<li>first</li><br />
<li>second</li><br />
</ul>
Any idea to prevent HTML parts to be line-breaked, but still allow the filter to do its job on plain text parts?
EDIT - #Shang Wang: The real-world usage for this filter is a backend for writers who are familiar with HTML and prefer not to use a rich text editor, but would still like to avoid typing "<br />" or "<p>" everytime they need to go to a newline.
Basically, what I'm trying to do is to emulate Drupal's "Filtered HTML" input filter, which is meant for editors who need a way to quickly write simple articles without using a WYSIWYG editor, but with the possibility to add more advanced HTML tags (like , , etc..) here and there.
Hope this helps to understand my goal, and sorry for my english.
EDIT 2 - #karison: I don't have a particular approach, yet. My current code is:
{{ myText | bleach | linebreaks }}
I'd like to avoid to write from scratch a custom filter just for this, so I don't have any code to show. As it's something that I've seen in Drupal and other CMS, I was hoping that there was some way to do it with the current linebreaks filter.
No I don't think it's possible and it doesn't make much sense. You could have new lines in your html section as well:
<p>This is a
multiple line text.
</p>
but they won't be shown as multiple lines when the browser is rendering them. Then what is the template filter suppose to do? I think the best option for you is to separate the text yourself in your views.
Edit:
First off I'm not aware of any such django template filter exists because your situation is too specific to make it a public template filter, also the requirement is complex and require a parser to distinguish between html and plain text.
Secondly, multi-line text is not rendered by inserting <br/> for each new line(w3school's doc). Instead you use the tag <pre></pre> to wrap your paragraph. In theory, for each block of plain text you could wrap <pre> around it, then the new lines will be shown "as is".

Why do my hyperlinks go to the wrong directory?

In my project functionality is like when i need to set a link to direct to:
/site/sales/sold.php
so the menu.php file link would look like this:
<ul>
<li>Sales</li>
<li>Sold Items</li>
</ul>
it would sometime direct to
/site/sales/sold.php
and the next moment, it repeats the menu's directory like:
/site/sales/sales/sold.php
so i removed the sales directory, as its directing there by itself, worked for a little while and now it directs to
/site/sold.php
which does not exist so it ends up with a 404.
If you are on a page sales/ and link to a page sales, the link will result in sales/sales/ – that is the defined behavior.
The default method to avoid that is to specify a base URL via the HTML <base> tag. There is no PHP, JS or CSS involved here – just good ol' HTML 2.0.
<base href="http://www.example.com/site/">
Using this in your pages head, will define the given URL as base for all links on the page, thus a link like sales/ will actually result in http://www.example.com/site/sales/ when clicked.
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
Why don't you just use absolute Links? Or even URL-rewriting?
The only way of using relative links like your "sold.php" is if your menu only occurs inside your /sales directory. If this menu comes up for example inside a page on /site, of course it won't work, because there probably isn't a file called "sold.php" under /site/sold.php. So if you wan't to make sure, your link "Sold" always points to the right direction, use a Link like /site/sales/sold.php. Then it won't matter if you are inside /site or even inside /site/sales.
if i for example set my menu link to direct to: /site/sales/sold.php so the menu.php file link would look like this:
<li>Sales</li>
<ul>
<li>Sold Items</li>
</ul>
This does not make sense. If you would point your link to /site/sales/sold.php, your link would look exactly like that: <li>Sold Items</li>

How to display html lists in IOS UITextField?

I see an entry here:
How to add bullets
It shows how to add bullets into IOS UITextField.
What I need is something different. I want to save the HTML code in the database like:
<ul>
<li>item1</li>
<li>item2</li>
</ul>
And then show it in IOS application as seen in the browser.
What is the good way of it?
I dont know if there is any such HTML interpreter/parser that will directly convert this code to NSString.
What I would suggest is that : Save the text in database as plane string with bullets or any prefix as <bullet>item1.
And while showing to the UI, first read that string from the database and replace <bullet> with some text as • (dot buttlet, Unicode code point U+2022).
Or you need to use regex to convert your HTML tag and then replace <li> with •
Am I missing something? Why not just UIWebView instead of UITextField?