A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

75 satır
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2012 Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. """
  23. This package contains :py:class:`~.Wikicode` "nodes", which represent a single
  24. unit of wikitext, such as a Template, an HTML tag, a Heading, or plain text.
  25. The node "tree" is far from flat, as most types can contain additional
  26. :py:class:`~.Wikicode` types within them - and with that, more nodes. For
  27. example, the name of a :py:class:`~.Template` is a :py:class:`~.Wikicode`
  28. object that can contain text or more templates.
  29. """
  30. from __future__ import unicode_literals
  31. from ..compat import str
  32. from ..string_mixin import StringMixIn
  33. __all__ = ["Node", "Text", "Argument", "Heading", "HTMLEntity", "Tag",
  34. "Template"]
  35. class Node(StringMixIn):
  36. """Represents the base Node type, demonstrating the methods to override.
  37. :py:meth:`__unicode__` must be overridden. It should return a ``unicode``
  38. or (``str`` in py3k) representation of the node. If the node contains
  39. :py:class:`~.Wikicode` objects inside of it, :py:meth:`__iternodes__`
  40. should be overridden to yield tuples of (``wikicode``,
  41. ``node_in_wikicode``) for each node in each wikicode, as well as the node
  42. itself (``None``, ``self``). If the node is printable, :py:meth:`__strip__`
  43. should be overridden to return the printable version of the node - it does
  44. not have to be a string, but something that can be converted to a string
  45. with ``str()``. Finally, :py:meth:`__showtree__` can be overridden to build
  46. a nice tree representation of the node, if desired, for
  47. :py:meth:`~.Wikicode.get_tree`.
  48. """
  49. def __unicode__(self):
  50. raise NotImplementedError()
  51. def __iternodes__(self, getter):
  52. yield None, self
  53. def __strip__(self, normalize, collapse):
  54. return None
  55. def __showtree__(self, write, get, mark):
  56. write(str(self))
  57. from . import extras
  58. from .text import Text
  59. from .argument import Argument
  60. from .heading import Heading
  61. from .html_entity import HTMLEntity
  62. from .tag import Tag
  63. from .template import Template