English 中文(简体)
How do you put HTML or XML into a YAML?
原标题:

I would like to store HTML snippets inside a YAML file. What is the best way to do that?

Something like:

myhtml: |
  <div>
    <a href="#">whatever</a>
  </div>
最佳回答

Example

Here is a sample record from a YAML-based snippet management system I created years ago:

- caption:    fieldset msie5
  tinycap:    fieldset
  domain:     html
  desc:       fieldset and legend tag
  wwbody: |
      <fieldset>
      <legend>legend</legend>

      </fieldset>

You can repeat that or something like it for all the snippets you want to manage. This particular system stores the snippets as an array of name-value pairs (Perl people would call this an AoH). If you do not need all this extra information, just two name-value pairs will suffice (e.g., caption + body).

The nice thing about this system: YAML indentation prevents "delimiter collision" problems. You never have to use clumsy escape sequences inside your snippet body.

Text Editor or IDE alternative

Note: Increasingly, text editors and IDEs support flexible snippet management options natively, so you may want to consider using the format of a text editor rather than re-inventing your own. If you do re-invent your own, you can write a script to translate your YAML format into the native format of a text editor if you later decide you want to do that.

See also:

问题回答

Use templates. We probably shan t mix to put HTML in .po files or in the data layer since escape and double escape (JavaScript escape) rather keep distinct presentation (view) and persistence (storage) layers. HTML is presentation and view, hence belongs to the presentation layer.





相关问题
Flex External Configuration File

My problem: I have a program in Flex3 that accesses a server. The program itself is on a server and accessed through a web browser. The point is that I don t want to hardcode in the swf file the IP of ...

Add an XML schema to Visual Studio

I want Intellisense support when writing App.config sections or XML configuration files for components like NHibernate, log4net, or Unity. What options do I have to get Visual Studio to find these ...

String format for Castle DictionaryAdapter

I m using Castle DictionaryAdapter in order to get the application settings from the app.config as an interface ( based on Getting rid of strings (3): take your app settings to the next level ): ...

AppSettings on a different .config file not being updated

I am trying to do the exact same thing mentioned on this recent previous question. In essence, here s the case (which is exactly my same situation): My plan is to have these (appSettings) in ...

How do you put HTML or XML into a YAML?

I would like to store HTML snippets inside a YAML file. What is the best way to do that? Something like: myhtml: | <div> <a href="#">whatever</a> </div>

AppConfig in a VS 2008 test project?

I ve just added my first test project to a VS 2008 solution. I have a component I d like to use in a unit test; the component calls System.Configuration.ConfigurationSettings.GetConfig() to get a ...

Why is a published website referencing my machine?

I have a website that I publish in Visual Studio 2008 and then send off to other people. One of the pages needs to alter a few configuration files, so an action is executed using ...

Updating AppSettings via ASP.NET MVC Controller

I m writing a basic little forums web app (for fun and to sharpen the ole saw), and I m having a bit of trouble with AppSettings. My plan is to have these settings in their own file (Settings.config)...

热门标签