Remove gratuitous use of kwargs in these methods, for readability.
Chris Pressey
3 months ago
135 | 135 | def global_link_ref_defs(self): |
136 | 136 | return self.link_ref_defs |
137 | 137 | |
138 | def to_json_data(self, **kwargs): | |
138 | def to_json_data(self, htmlize=False, ordered=False, link_ref_defs=None): | |
139 | 139 | preamble = self.preamble.strip() |
140 | 140 | properties = self.properties |
141 | 141 | |
142 | if kwargs.get("htmlize", False): | |
143 | if "link_ref_defs" not in kwargs: | |
144 | kwargs["link_ref_defs"] = self.global_link_ref_defs() | |
145 | preamble = markdown_to_html5( | |
146 | preamble, link_ref_defs=kwargs["link_ref_defs"] | |
142 | if htmlize: | |
143 | if not link_ref_defs: | |
144 | link_ref_defs = self.global_link_ref_defs() | |
145 | preamble = markdown_to_html5(preamble, link_ref_defs=link_ref_defs) | |
146 | properties = markdown_to_html5_deep( | |
147 | self.properties, link_ref_defs=link_ref_defs | |
147 | 148 | ) |
148 | properties = markdown_to_html5_deep( | |
149 | self.properties, link_ref_defs=kwargs["link_ref_defs"] | |
150 | ) | |
151 | ||
152 | if kwargs.get("ordered", False): | |
149 | ||
150 | if ordered: | |
153 | 151 | properties_list = [] |
154 | 152 | for key, value in properties.items(): |
155 | 153 | properties_list.append([key, value]) |
162 | 160 | "title": self.title, |
163 | 161 | "properties": properties, |
164 | 162 | "preamble": preamble, |
165 | "sections": [s.to_json_data(**kwargs) for s in self.sections], | |
163 | "sections": [ | |
164 | section.to_json_data( | |
165 | htmlize=htmlize, ordered=ordered, link_ref_defs=link_ref_defs | |
166 | ) | |
167 | for section in self.sections | |
168 | ], | |
166 | 169 | } |
167 | 170 | |
168 | 171 | |
237 | 240 | title = re.sub(r"[^\w\s\/\.\'-]", "", title) |
238 | 241 | return re.sub(r"[\s\/\.\'-]+", "-", title) |
239 | 242 | |
240 | def to_json_data(self, **kwargs): | |
243 | def to_json_data(self, htmlize=False, ordered=False, link_ref_defs=None): | |
241 | 244 | body = self.body |
242 | 245 | properties = self.properties |
243 | 246 | |
244 | if kwargs.get("htmlize", False): | |
245 | body = markdown_to_html5(body, link_ref_defs=kwargs["link_ref_defs"]) | |
247 | if htmlize: | |
248 | body = markdown_to_html5(body, link_ref_defs=link_ref_defs) | |
246 | 249 | properties = markdown_to_html5_deep( |
247 | self.properties, link_ref_defs=kwargs["link_ref_defs"] | |
250 | self.properties, link_ref_defs=link_ref_defs | |
248 | 251 | ) |
249 | 252 | |
250 | if kwargs.get("ordered", False): | |
253 | if ordered: | |
251 | 254 | properties_list = [] |
252 | 255 | for key, value in properties.items(): |
253 | 256 | properties_list.append([key, value]) |