@@ -140,6 +140,10 @@ def convert_to_html(data: Dict[str, Any], apply_amendments: bool = False, up_to_
140140
141141 # Format the content text
142142 formatted_text = format_sfs_text_as_markdown (innehall_text , apply_links = True )
143+
144+ # Apply section tags for HTML export (preserve selex tags)
145+ from formatters .format_sfs_text import parse_logical_sections
146+ formatted_text = parse_logical_sections (formatted_text )
143147
144148 # Apply amendments if requested
145149 if apply_amendments and up_to_amendment :
@@ -226,6 +230,7 @@ def convert_to_html(data: Dict[str, Any], apply_amendments: bool = False, up_to_
226230 return html_doc
227231
228232
233+
229234def make_links_relative (html_content : str ) -> str :
230235 """
231236 Strip base URL from links to make them relative for HTML export.
@@ -247,28 +252,47 @@ def make_links_relative(html_content: str) -> str:
247252
248253def markdown_to_html (markdown_text : str ) -> str :
249254 """Convert markdown formatting to HTML using the markdown library.
255+
256+ Preserves selex tags (<section>, <article>) and their attributes.
250257
251258 Args:
252259 markdown_text: Text with markdown formatting
253260
254261 Returns:
255262 str: HTML formatted text
256263 """
264+ # Pre-process: Mark selex tags for markdown processing
265+ processed_text = prepare_markdown_with_selex_tags (markdown_text )
266+
257267 # Configure markdown with useful extensions
258268 md = markdown .Markdown (
259269 extensions = [
260270 'tables' , # Support for tables
261- 'nl2br' , # Convert newlines to <br>
262271 'attr_list' , # Support for {: .class} attributes
272+ 'md_in_html' , # Allow markdown inside HTML blocks
263273 ]
264274 )
265275
266276 # Convert markdown to HTML
267- html_content = md .convert (markdown_text )
277+ html_content = md .convert (processed_text )
268278
269279 return html_content
270280
271281
282+ def prepare_markdown_with_selex_tags (markdown_text : str ) -> str :
283+ """
284+ Prepare markdown text with selex tags for proper markdown processing.
285+
286+ The md_in_html extension requires markdown="1" attribute on HTML block elements
287+ to process markdown content inside them.
288+ """
289+ # Add markdown="1" to section and article tags
290+ processed = re .sub (r'<(section[^>]*)>' , r'<\1 markdown="1">' , markdown_text )
291+ processed = re .sub (r'<(article[^>]*)>' , r'<\1 markdown="1">' , processed )
292+
293+ return processed
294+
295+
272296def create_ignored_html_content (data : Dict [str , Any ], reason : str ) -> str :
273297 """Create simplified HTML for ignored documents.
274298
@@ -594,6 +618,34 @@ def get_common_styles() -> str:
594618 padding: 10px 0 6px 0;
595619 }}
596620
621+ /* Selex section styling */
622+ article {{
623+ margin: 20px 0;
624+ }}
625+
626+ section {{
627+ margin: 15px 0;
628+ }}
629+
630+ section.kapitel {{
631+ margin: 25px 0;
632+ padding: 10px 0;
633+ }}
634+
635+ section.paragraf {{
636+ margin: 15px 0;
637+ }}
638+
639+ section[status="upphavd"] {{
640+ opacity: 0.6;
641+ text-decoration: line-through;
642+ }}
643+
644+ section[status="ikraft"] {{
645+ border-left: 3px solid var(--selex-light-blue);
646+ padding-left: 15px;
647+ }}
648+
597649 /* Markdown content styling */
598650 table {{
599651 border-collapse: collapse;
0 commit comments