org_reader.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2017 Sébastien Gendre
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. import re
  13. from orgpython import org_to_html
  14. from pelican import signals
  15. from pelican.readers import BaseReader
  16. from pelican.utils import pelican_open
  17. class OrgReader(BaseReader):
  18. """Reader for Org files"""
  19. enabled = True
  20. file_extensions = ['org']
  21. def _separate_header_and_content(self, text_lines):
  22. """
  23. From a given Org text, return the header separate from the content.
  24. The given text must be separate line by line and be a list.
  25. The return is a list of two items: header and content.
  26. Theses two items are text separate line by line in format of a list
  27. Keyword Arguments:
  28. text_lines -- A list, each item is a line of the texte
  29. Return:
  30. [
  31. header -- A list, each item is a line of the texte
  32. content -- A list, each item is a line of the texte
  33. ]
  34. """
  35. no_more_header = False
  36. header = []
  37. content = []
  38. for line in text_lines:
  39. metadata = re.match(r'^#\+[a-zA-Z]+:.*', line)
  40. if metadata and not no_more_header:
  41. header.append(line)
  42. else:
  43. no_more_header = True
  44. content.append(line)
  45. return header, content
  46. def _parse_metadata(self, text_lines):
  47. """
  48. From a given Org text, return the metadatas
  49. Keyword Arguments:
  50. text_lines -- A list, each item is a line of the texte
  51. Return:
  52. A dict containing metadatas
  53. """
  54. pass
  55. def read(self, source_path):
  56. """
  57. Parse content and metadata of Org files
  58. Keyword Arguments:
  59. source_path -- Path to the Org file to parse
  60. """
  61. pass