@@ -64,43 +64,47 @@ def register_extra_dependencies(self, post):
64
64
"""Adds dependency to post object to check .dep file."""
65
65
post .add_dependency (lambda : self ._read_extra_deps (post ), 'fragment' )
66
66
67
- def compile_html (self , source , dest , is_two_file = True ):
68
- """Compile reSt into HTML."""
67
+ def compile_html_string (self , data , source_path = None , is_two_file = True ):
68
+ """Compile reSt into HTML strings."""
69
+ add_ln = 0
70
+ if not is_two_file :
71
+ spl = re .split ('(\n \n |\r \n \r \n )' , data , maxsplit = 1 )
72
+ data = spl [- 1 ]
73
+ if len (spl ) != 1 :
74
+ # If errors occur, this will be added to the line
75
+ # number reported by docutils so the line number
76
+ # matches the actual line number (off by 7 with default
77
+ # metadata, could be more or less depending on the post
78
+ # author).
79
+ add_ln = len (spl [0 ].splitlines ()) + 1
80
+
81
+ default_template_path = os .path .join (os .path .dirname (__file__ ), 'template.txt' )
82
+ output , error_level , deps = rst2html (
83
+ data , settings_overrides = {
84
+ 'initial_header_level' : 1 ,
85
+ 'record_dependencies' : True ,
86
+ 'stylesheet_path' : None ,
87
+ 'link_stylesheet' : True ,
88
+ 'syntax_highlight' : 'short' ,
89
+ 'math_output' : 'mathjax' ,
90
+ 'template' : default_template_path ,
91
+ }, logger = self .logger , source_path = source_path , l_add_ln = add_ln , transforms = self .site .rst_transforms )
92
+ if not isinstance (output , unicode_str ):
93
+ # To prevent some weird bugs here or there.
94
+ # Original issue: empty files. `output` became a bytestring.
95
+ output = output .decode ('utf-8' )
96
+ return output , error_level , deps
69
97
98
+ def compile_html (self , source , dest , is_two_file = True ):
99
+ """Compile reSt into HTML files."""
70
100
if not has_docutils :
71
101
req_missing (['docutils' ], 'build this site (compile reStructuredText)' )
72
102
makedirs (os .path .dirname (dest ))
73
103
error_level = 100
74
104
with io .open (dest , "w+" , encoding = "utf8" ) as out_file :
75
105
with io .open (source , "r" , encoding = "utf8" ) as in_file :
76
106
data = in_file .read ()
77
- add_ln = 0
78
- if not is_two_file :
79
- spl = re .split ('(\n \n |\r \n \r \n )' , data , maxsplit = 1 )
80
- data = spl [- 1 ]
81
- if len (spl ) != 1 :
82
- # If errors occur, this will be added to the line
83
- # number reported by docutils so the line number
84
- # matches the actual line number (off by 7 with default
85
- # metadata, could be more or less depending on the post
86
- # author).
87
- add_ln = len (spl [0 ].splitlines ()) + 1
88
-
89
- default_template_path = os .path .join (os .path .dirname (__file__ ), 'template.txt' )
90
- output , error_level , deps = rst2html (
91
- data , settings_overrides = {
92
- 'initial_header_level' : 1 ,
93
- 'record_dependencies' : True ,
94
- 'stylesheet_path' : None ,
95
- 'link_stylesheet' : True ,
96
- 'syntax_highlight' : 'short' ,
97
- 'math_output' : 'mathjax' ,
98
- 'template' : default_template_path ,
99
- }, logger = self .logger , source_path = source , l_add_ln = add_ln , transforms = self .site .rst_transforms )
100
- if not isinstance (output , unicode_str ):
101
- # To prevent some weird bugs here or there.
102
- # Original issue: empty files. `output` became a bytestring.
103
- output = output .decode ('utf-8' )
107
+ output , error_level , deps = self .compile_html_string (data , source , is_two_file )
104
108
out_file .write (output )
105
109
deps_path = dest + '.dep'
106
110
if deps .list :
0 commit comments