Build a markup language for your ASP Website System

Source: Internet
Author: User

Online Editing is inevitable during the construction of dynamic websites.Article. Html provides a textarea tag, but it does not actually solve this problem, because the text from textarea is plain text. Unless HTML tags are used during input, a text disk with no structure from start to end will be obtained during output. In web design, DHTML is used to construct a kind of WYSIWYG online editor to solve this problem.

However, WYSIWYG is not the only solution. I found that some online editors of portal websites have their own characteristics during the Internet access process. It is not WYSIWYG (but provides a preview function), but a text field of textarea, but does not support HTML markup language. Instead, it has its own set of Markup languages.

Figure 1

Figure 2
I think it is very smooth, and its advantages are summarized as follows:

First, there are not many tags, which is very simple compared with HTML, and paragraph can be automatically generated by carriage return, which is easy to be accepted by general users. I believe that if the Chinese mark is used, it can be accepted by more domestic users.

Second, users can better master their article structures and generate less garbled characters than what you see is what you get.

Third, the visibility is much better than HTML, and the preview function is better.

Fourth, because your markup language does not support scripts, it is safer.

After some thought and practice, I have publicized the method of constructing my own markup language:

First, we determine a simple and necessary markup language for our website. When determining, omit unnecessary content. For me, the markup language I have determined for my website is as follows:

[Image] image URL [/image]
[Title] text content [/Title]
[Subtitle] text content [/subtitle] (Added considering the user may be subdivided)
[Bold] text content [/bold]
[Italic] text content [/italic]
[LINK] URL [/link]

Then, we provide a certain mechanism for the browser to understand our markup. So, how can the browser understand the markup we have determined? On the content display page, we need to writeProgramTranslate all our tags into standard HTML tags, but you must filter out the HTML tags imported by users.Code.

Step 1: filter HTML code.

This is actually very simple. You only need to replace all the "<" labels with "<", and replace all ">" with ">. Use the following statement in ASP:

Content = Replace (content, "<", "<")

Content = Replace (content, ">", "> ")

(In the above Code, content is a variable that stores the content we want to display. If it appears below, it also means the same .)

Step 2: translate our tag into HTML

This is relatively complicated, because it is not simple to replace all [tags with <and] with> and then translate the Chinese (comparison) into English (such as IMG) you can. There are two reasons:

1 is the content in our tag, which needs to be processed according to different categories:

The first type is directly displayed to the user, for example:

[Title] Text [/Title]

In this case, you only need to translate the tag into English. For example, the above tag is translated into

The second type is not directly presented to the user, for example:

[Image] image URL [/image]

In this case, the content "image URL" in the middle of the tag is only the URL we want to display. in HTML, It is the src attribute of the tag, in addition, this tag does not end with a tag in HTML. therefore, the direct translation result is definitely incorrect.

Category 3: directly present and act as attributes, for example:

[LINK] URL [/link]

2. Not all items marked are translated. For example, sometimes users need to use the symbol "[" and symbol "]" to express their content, at this time, if you translate the mark into "<" and ">", it is definitely not in line with the user's mind.

After analyzing the problems, I will give a reference to programming ideas and a reference program below.

Because different tags require different translation methods, different tags must be translated one by one.

For any single tag, this may or may not appear once in an article, the program should first check the position where the starting mark (for example, "image"] image Address [/image] "is" [Image] ") appears from start to end, check the end mark from that position. If the mark is also checked, it indicates that this is the mark we want. If the end mark is not checked, it indicates that it is not the mark we want, it is only the content displayed by the user. After checking, the tag is translated as an HTML tag, and the content in the tag is processed differently based on different types. After sitting, the check continues from the position of the tag to the end of the article.

Recursion is required in actual writing. The following is an example program for translating the [Image] image Address [/image] Mark.

Function translateimg (STR)
Start = instr (STR, "[Image]") 'Check the start position of the tag
If start = 0 Then exit function ', the start position is 0, indicating that the program ends without this mark.
End = instr (START, STR, "[/image]" 'Check the end mark position after the start position
If end = 0 Then exit function' the position where the end mark appears is 0, indicating that no end mark is displayed and the program ends.
Midstr = mid (STR, start + 4, end-start-4) 'indicates the content in the middle.
Replacestr = mid (STR, start, end-start + 5) 'to mark the content in the middle and use it as the content to be replaced.
STR = Replace (instr, replacestr, "Translateimg STR 'recursively execute this function
End Function

Through the above analysis, we believe that readers can build a "myhtml" markup language for their websites through their own analysis.

In actual development, some issues need to be cracked, such as tag nesting; it is translated before the user is submitted to the database or when the user browsed the article is called up from the database. It provides users with automatic insert button to facilitate user operation experience login. this article is only intended to attract readers to appreciate it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.