mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-06 16:08:43 +02:00
gdbus-codegen: preserve relative indentation in doc comments
This commit also changes the generators for rst, xml and dockbook to preserve indentation. Closes #3032
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import re
|
||||
import textwrap
|
||||
from os import path
|
||||
|
||||
from . import utils
|
||||
@@ -340,12 +341,12 @@ class DocbookCodeGenerator:
|
||||
return s
|
||||
|
||||
def expand_paras(self, s, expandParamsAndConstants):
|
||||
s = self.expand(s, expandParamsAndConstants).strip()
|
||||
s = textwrap.dedent(self.expand(s, expandParamsAndConstants)).rstrip()
|
||||
res = []
|
||||
if not s.startswith("<para>"):
|
||||
res.append("<para>")
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
line = line.rstrip()
|
||||
if not line:
|
||||
line = "</para><para>"
|
||||
res.append(line)
|
||||
|
@@ -7,6 +7,7 @@ import os
|
||||
import re
|
||||
|
||||
from . import utils
|
||||
import textwrap
|
||||
|
||||
# Disable line length warnings as wrapping the templates would be hard
|
||||
# flake8: noqa: E501
|
||||
@@ -22,8 +23,8 @@ class MdCodeGenerator:
|
||||
def _expand(self, s, expandParamsAndConstants):
|
||||
"""Expands parameters and constant literals."""
|
||||
res = []
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
for line in textwrap.dedent(s).split("\n"):
|
||||
line = line.rstrip()
|
||||
if line == "":
|
||||
res.append("")
|
||||
continue
|
||||
|
@@ -6,6 +6,7 @@ import os
|
||||
import re
|
||||
|
||||
from . import utils
|
||||
import textwrap
|
||||
|
||||
# Disable line length warnings as wrapping the templates would be hard
|
||||
# flake8: noqa: E501
|
||||
@@ -21,8 +22,8 @@ class RstCodeGenerator:
|
||||
def _expand(self, s, expandParamsAndConstants):
|
||||
"""Expands parameters and constant literals."""
|
||||
res = []
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
for line in textwrap.dedent(s).split("\n"):
|
||||
line = line.rstrip()
|
||||
if line == "":
|
||||
res.append("")
|
||||
continue
|
||||
|
@@ -20,6 +20,7 @@
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import xml.parsers.expat
|
||||
import textwrap
|
||||
|
||||
from . import dbustypes
|
||||
from .utils import print_error
|
||||
@@ -64,14 +65,12 @@ class DBusXMLParser:
|
||||
|
||||
def handle_comment(self, data):
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BEGIN
|
||||
lines = data.split("\n")
|
||||
lines = textwrap.dedent(data).split("\n")
|
||||
symbol = ""
|
||||
body = ""
|
||||
in_para = False
|
||||
params = {}
|
||||
for line in lines:
|
||||
orig_line = line
|
||||
line = line.lstrip()
|
||||
if comment_state == DBusXMLParser.COMMENT_STATE_BEGIN:
|
||||
if len(line) > 0:
|
||||
colon_index = line.find(": ")
|
||||
@@ -95,7 +94,7 @@ class DBusXMLParser:
|
||||
if not in_para:
|
||||
body += "\n"
|
||||
in_para = True
|
||||
body += f"{orig_line}\n"
|
||||
body += f"{line}\n"
|
||||
else:
|
||||
param = line[1:colon_index]
|
||||
docs = line[colon_index + 2 :]
|
||||
@@ -106,12 +105,12 @@ class DBusXMLParser:
|
||||
if not in_para:
|
||||
body += "\n"
|
||||
in_para = True
|
||||
body += orig_line + "\n"
|
||||
body += line + "\n"
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_BODY:
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
in_para = True
|
||||
body += orig_line + "\n"
|
||||
body += line + "\n"
|
||||
else:
|
||||
if in_para:
|
||||
body += "\n"
|
||||
|
Reference in New Issue
Block a user