1

Is this possible to do own entities?

Like: &longline; --> -----------------------------

then use it in html code:

<div>
    &longline;
    bla bl bla
</div>

4 Answers 4

2

It's possible in XML using the <!ENTITY> declaration, but I wouldn't recommend it. Your site would no longer be HTML, and most browsers wouldn't accept it. (Indeed, none do, unless your file is XML, which rather defeats the purpose.) Client-side processing using JavaScript is possible, but not accessible. Server-side processing is a waste of time, unless it's user input, in which case you should replace the entities before inserting the data into your database.

So, yes, it's possible, but unless you have a good reason to do it... don't!

Sign up to request clarification or add additional context in comments.

Comments

1

No.

If you're using a server-side language, you can use a string replace function in that language (PHP, C#, Java, Ruby, etc.), but not in pure HTML.

Comments

1

Not possible with HTML, but best way to achieve this would be server side scripting, so that the user receives pure well formed HTML, but gives the developer the freedom to use methods like what you want to do to generate the HTML.

PHP could do this by caching the output, then replacing all occurrences with your new string.

Comments

1

No, not in pure HTML.

However, this desired behaviour could be achieved with javascript (or PHP, python, ruby). You could scan all the text nodes with it and replace accordingly.

However, I hardly see why would you like such behaviour. I think you should use propperly styled <hr> element. CSS support border: 1px dashed black; so it would look like many dashes (-).

Php also has function str_repeat('-', 30);. That would make 30 dashes, but it has to be replaced server-side.

3 Comments

Oh no :( I thought i have seen feature like i need, but i was long time ago and it was just my imagination i think. #edit: hey that line was just example. I triedt to use entity like that: &ArgumetnNullException; to make a link to msdn. #edit: also foud like this: w3schools.com/dtd/dtd_entities.asp . So wecan make entities but it is not html5 :/
Well, maybe if you tell what is the desired behaviour you want to achieve, we might provide another solution.
Yes, but it has really questionable browser support. If you have to do it, I'd do it with javascript. It is pretty simple with jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.