如何在数据库中存储轻量级格式化(Textile, Markdown)?[英] How to store lightweight formatting (Textile, Markdown) in database?

本文是小编为大家收集整理的关于如何在数据库中存储轻量级格式化(Textile, Markdown)?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我将在我正在研究的项目中实现一种轻量级格式化语言(可能是纺织品,也许是Markdown),我想知道如何最好地将其存储在数据库中.

如果用户能够编辑其发布的内容,则对我来说,存储原始的,未转换的标记是有意义的,这样用户下次不必在下一次编辑HTML.但是,由于内容将比编辑要多得多,因此存储内容的转换副本也有意义

那么,是否可以将原始内容并排存储在数据库中?有更好的方法吗?

谢谢!

推荐答案

存储标记:

  • 每个视图=转换
  • 每个编辑=无处理

存储html

  • 每个视图=无处理
  • 每个编辑=转换为Markdown和Back

存储两个

  • 每个视图=无处理
  • 每个编辑=编辑后转换为HTML

您必须权衡处理成本与存储成本.

其他推荐答案

您应该确定存储原始纺织品/标记标记,并使用标准的HTTP缓存内容(最后修饰,到期,at,atag)来缓存呈现页面或只是缓存处理标记的结果.

其他推荐答案

我目前正在使用PHP的Markdown.我将Markdown-Source存储在数据库中,并根据要求显示转换版本.我没有性能问题,对此设置感到非常满意.

本文地址:https://www.itbaoku.cn/post/597543.html

问题描述

I'm going to be implementing a lightweight formatting language (probably Textile, maybe Markdown) in a project I'm working on, and I'm wonder how best to store it in the database.

If the user is able to edit the content they're posting, it makes sense to me that the original, non-converted markup be stored so that the user doesn't have to edit HTML the next time around. But since the content is going to be displayed a whole lot more than edited, it also makes sense to store a converted copy of the content so that the original doesn't have to be sent through Textile on every page view.

So, is the common practice to store both the original and converted content side-by-side in the database? Is there a better way?

Thanks!

推荐答案

Store markdown:

  • Every view = conversion
  • Every edit = no processing

Store html

  • Every view = no processing
  • Every edit = convert to markdown and back

Store both

  • Every view = no processing
  • Every edit = convert to html after edit

You have to weigh up your processing costs vs. your storage cost.

其他推荐答案

You should definetly store original Textile/Markdown markup and use either standard HTTP caching stuff (Last-modified, Expires-At, ETag) to cache rendered pages or just cache the result of processing markup.

其他推荐答案

I'm currently using Markdown with PHP. I store the markdown-source in the database, and I display the Converted Version upon request. I have no performance issues, and am very happy with this setup.