Changes between Version 19 and Version 20 of GenshiFaq
- Timestamp:
- Sep 11, 2006, 2:15:18 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenshiFaq
v19 v20 1 1 = Frequently Asked Questions = 2 2 3 Here you can find answers to frequently asked questions about Markup.3 Here you can find answers to frequently asked questions about Genshi. 4 4 5 5 [[PageOutline(2-3, Overview, inline)]] … … 7 7 == General == 8 8 9 === What is Markup? ===9 === What is Genshi? === 10 10 11 We like to call it a ''“toolkit for stream-based generation of markup for the web”''. The largest feature provided by Markup is an XML-based template engine that is heavily inspired by [http://kid-templating.org/ Kid].11 We like to call it a ''“toolkit for stream-based generation of output for the web”''. The largest feature provided by Genshi is an XML-based template engine that is heavily inspired by [http://kid-templating.org/ Kid]. But it also provides a text-based template engine, as well as a collection of tools for working with markup. 12 12 13 13 === Why yet another template engine? === … … 38 38 We felt these problems would best be addressed by developing a new engine form scratch, as opposed to trying to “fix” Kid. 39 39 40 === What are the main differences between Kid and Markup? ===40 === What are the main differences between Kid and Genshi? === 41 41 42 Markup executes templates directly, there's no code generation phase. Expressions are evaluated in a more forgiving way using AST transformation. Template variables are stored on a stack, which means that some variable set in a loop deep in the template won't leak into the rest of the template. And even though Markup doesn't generate Python code for templates, it generally [wiki:MarkupPerformance performs] slightly better than Kid (even up to 2x in [source:/trunk/examples/basic/ some of our tests], but the exact differences depend on a lot of factors).42 Genshi executes templates directly, there's no code generation phase. Expressions are evaluated in a more forgiving way using AST transformation. Template variables are stored on a stack, which means that some variable set in a loop deep in the template won't leak into the rest of the template. And even though Genshi doesn't generate Python code for templates, it generally [wiki:GenshiPerformance performs] slightly better than Kid (even up to 2x in [source:/trunk/examples/basic/ some of our tests], but the exact differences depend on a lot of factors). 43 43 44 Markupdoes not depend on !ElementTree. It uses Expat for parsing XML, and is based on streaming slightly abstracted parse events through the processing pipeline. It uses [http://www.w3.org/TR/xinclude/ XInclude] – instead of Kids' `py:extends` – to allow template authors to factor out common bits. For match templates, it uses [http://www.w3.org/TR/xpath XPath] expressions instead of the !ElementTree API.44 Genshi does not depend on !ElementTree. It uses Expat for parsing XML, and is based on streaming slightly abstracted parse events through the processing pipeline. It uses [http://www.w3.org/TR/xinclude/ XInclude] – instead of Kids' `py:extends` – to allow template authors to factor out common bits. For match templates, it uses [http://www.w3.org/TR/xpath XPath] expressions instead of the !ElementTree API. 45 45 46 For more details about what's different see MarkupVsKid.46 For more details about what's different see GenshiVsKid. 47 47 48 48 === What other features does the toolkit provide? === 49 49 50 Beyond the template engine, Markupprovides:50 Beyond the XML-based template engine, Genshi provides: 51 51 * a [MarkupStream unified stream-based processing model] for markup, where 52 52 * streams can come from XML or HTML text, or be [MarkupBuilder generated programmatically] using a very simple syntax. 53 53 * [MarkupPath XPath] can be used to query any stream, not just in templates. 54 * Different serialization methods (XML and HTML) for streams.54 * Different serialization methods (XML, HTML, and plain text) for streams. 55 55 * An HTML “sanitizing” filter to strip potentially dangerous elements or attributes from user-submitted HTML markup. 56 * A simple text-based template engine that can be used for generating plain text output. 56 57 57 58 === Why use includes instead of inheritance? === … … 59 60 We think that includes are both simpler and more natural for templating. 60 61 61 Template inheritance is a concept that fits well with template languages where a master template provide “slots” that are “filled” by the inheriting templates. However, Markup has no such feature, and instead uses the more powerful and flexible concept of [wiki:MarkupTemplates#py:match match templates].62 Template inheritance is a concept that fits well with template languages where a master template provide “slots” that are “filled” by the inheriting templates. However, Genshi has no such feature, and instead uses the more powerful and flexible concept of [wiki:GenshiTemplates#py:match match templates]. 62 63 63 64 Furthermore, [http://www.w3.org/TR/xinclude/ XInclude] is a [http://www.w3.org/ W3C] standard, which means that it is more likely to be supported in authoring tools than some esoteric custom notation for including external resources. 64 65 65 ''See also MarkupRecipes/PyExtendsEquivalent and MarkupRecipes/PyLayoutEquivalent to find out how the Kid directives `py:extends` and `py:layout` map to includes in Markup.''66 ''See also GenshiRecipes/PyExtendsEquivalent and GenshiRecipes/PyLayoutEquivalent to find out how the Kid directives `py:extends` and `py:layout` map to includes in Genshi.'' 66 67 67 68 [[Image(http://static.edgewall.org/gfx/opensource-75x65.png, width=75, height=65, align=right)]] 68 === What license governs the use of Markup? ===69 === What license governs the use of Genshi? === 69 70 70 Markupis released under the [wiki:License revised BSD license], which is a liberal open source license that has been [http://opensource.org/licenses/bsd-license.php approved] by the [http://opensource.org/ Open Source Initiative (OSI)].71 Genshi is released under the [wiki:License revised BSD license], which is a liberal open source license that has been [http://opensource.org/licenses/bsd-license.php approved] by the [http://opensource.org/ Open Source Initiative (OSI)]. 71 72 72 === What do I need to use Markup? ===73 === What do I need to use Genshi? === 73 74 74 75 Python 2.3 or later. Python 2.4 is recommended for better performance, plus error messages will include template line numbers and column offsets. [http://peak.telecommunity.com/DevCenter/setuptools Setuptools] is optional and only used for installation if it's available. 75 76 76 The template engine plugin (for http://www.turbogears.org/docs/plugins/template.html), which enables usage of Markup in frameworks such as [http://www.turbogears.com/ TurboGears], depends on Setuptools at runtime and installation time. Use of the plugin implementation is optional, though: Setuptools is ''not'' required for using Markupdirectly.77 The template engine plugin (for http://www.turbogears.org/docs/plugins/template.html), which enables usage of Genshi in frameworks such as [http://www.turbogears.com/ TurboGears], depends on Setuptools at runtime and installation time. Use of the plugin implementation is optional, though: Setuptools is ''not'' required for using Genshi directly. 77 78 78 === Wh at's up with the name? It's not possible to google for it!===79 === Why is it called “Genshi”? === 79 80 80 We're aware of the problem. Frankly, finding a good name that is sufficiently unique but doesn't sound cheesy is really hard. 81 “Genshi” (原糸) is japanese and roughly translates to “thread for weaving”. Basically, Genshi is a ''thread for weaving web output''. The thread meaning also fits nicely 82 with how markup is presented as streams of events in Genshi. 81 83 82 We're really open for suggestions though! If you have a good idea for a name, please bring it up on the [MailingList mailing list], [IrcChannel IRC channel], or the NameSuggestions wiki page. This project is still young, so changing the name at this point is certainly doable. 83 84 Prior to release 0.3, the project was called “Markup”. The name was changed because: 85 * there was [http://markup.sourceforge.net/ another Python project] using the name, 86 * it made communication somewhat awkward, because it was sometimes unclear whether someone is talking about the project “Markup”, or just plain markup, and 87 * it was not easy to find the project via search engines. 84 88 85 89 == Usage == … … 87 91 === How can I include literal XML in template output? === 88 92 89 Unless explicitly told otherwise, Markupescapes any data you substitute into template output so that it is safe for being parsed and displayed by web browsers and other tools. This saves you from the work of having to tediously escape every variable by hand, and greatly reduces the risk of introducing vectors for [http://ha.ckers.org/xss.html cross-site scripting (XSS)] attacks.93 Unless explicitly told otherwise, Genshi escapes any data you substitute into template output so that it is safe for being parsed and displayed by web browsers and other tools. This saves you from the work of having to tediously escape every variable by hand, and greatly reduces the risk of introducing vectors for [http://ha.ckers.org/xss.html cross-site scripting (XSS)] attacks. 90 94 91 95 However, sometimes what you want is to include text in the template output that should ''not'' get escaped. For example, if you allow users to enter HTML verbatim (or provide a rich-text editor of sorts), you want that HTML to appear as actual markup in the output, not as escaped text. 92 96 93 Markupprovides a number of ways to do that:94 * The `Markup` class in the [ApiDocs/ MarkupCore markup.core] module can be used to flag strings that should not be escaped. Strings wrapped in a `Markup` instance get copied to the output unchanged.95 * The `XML` and `HTML` functions in the [ApiDocs/ MarkupInput markup.input] module parse XML and HTML strings, respectively, and produce a [MarkupStream markup stream]. Note that this option can be rather expensive, as the text needs to be parsed just to be serialized again. Also, this method fails on bad markup that cannot be parsed by either [http://docs.python.org/lib/module-HTMLParser.html HTMLParser] or [http://docs.python.org/lib/module-xml.parsers.expat.html Expat].96 * If you are generating the snippets in question yourself, you may want to use the [ApiDocs/ MarkupBuilder markup.builder] to [MarkupBuilder generate markup streams programmatically]. Just as the results of the `XML` and `HTML` functions discussed above, the stream produced using `markup.builder` will not be escaped in the template output.97 Genshi provides a number of ways to do that: 98 * The `Markup` class in the [ApiDocs/GenshiCore genshi.core] module can be used to flag strings that should not be escaped. Strings wrapped in a `Markup` instance get copied to the output unchanged. 99 * The `XML` and `HTML` functions in the [ApiDocs/GenshiInput genshi.input] module parse XML and HTML strings, respectively, and produce a [GenshiStream markup stream]. Note that this option can be rather expensive, as the text needs to be parsed just to be serialized again. Also, this method fails on bad markup that cannot be parsed by either [http://docs.python.org/lib/module-HTMLParser.html HTMLParser] or [http://docs.python.org/lib/module-xml.parsers.expat.html Expat]. 100 * If you are generating the snippets in question yourself, you may want to use the [ApiDocs/GenshiBuilder genshi.builder] to [GenshiBuilder generate markup streams programmatically]. Just as the results of the `XML` and `HTML` functions discussed above, the stream produced using `genshi.builder` will not be escaped in the template output. 97 101 98 102 ---- 99 See also: MarkupGuide, MarkupRecipes103 See also: GenshiGuide, GenshiRecipes