开发者

What is the right method for parsing a blog post?

开发者 https://www.devze.com 2023-02-04 20:33 出处:网络
Need a guide line .... I am trying to write a personal blog. What is the standard structure for for input for the post.

Need a guide line ....

I am trying to write a personal blog. What is the standard structure for for input for the post. I am trying the format like:

This is the simple text
And I am [b] bold text[/b开发者_如何学编程].
This is the code part:
[code lang=java]
public static void main (String args[]) {
   System.out.println("Hello World!");
}
[/code]

Is this the right way to store post in the database?

And What is the right method to parse this kind of post? Shall I use regular expression to parse this or there is another standard for this. If the above mentioned format is not the right way for storage, then what it could be?

Thanks


Seems to me you are looking for something like BBCode

Take a look on the link, there are several libraries that do this. One example (from Wikipedia):

  • https://javabbcode.dev.java.net/

Disclaimer: Not tested myself

Also take a look on this question: Java BBCode library

Edit: Additional points

  • From my experience BBCode is too weak for writing blog also its syntax is little bit annoying
  • I would suggest go for Markdown - the same syntax Stackoverflow uses or even for reach text editor like TinyMCE - depending on what you are looking for.
  • It is better to use one of the existing text formats as if you would like to migrate the content to other system it would be easier to find filters for this purpose.


Have you considered using an existing dialect like markdown or textile? Both are feature rich in terms of supported markup, implementations are available in a plethora of languages, both for markdown and textile.


[1]: http://daringfireball.net/projects/markdown/

[2]: http://www.textism.com/tools/textile/

[3]: http://en.wikipedia.org/wiki/Markdown#Alternate_implementations

[4]: http://www.oreillynet.com/onlamp/blog/2007/05/praising_textile_1.html


XML is probably the best format for storing the post body, and there are many standard libraries for parsing it.

0

精彩评论

暂无评论...
验证码 换一张
取 消