Skip to content

Commit 7b0ad1b

Browse files
committed
fix code snippet and do not display cpp code in sip files
1 parent 64c99e0 commit 7b0ad1b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

scripts/sipify.pl

+18-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use constant MULTILINE_METHOD => 21;
1919
use constant MULTILINE_CONDITIONAL_STATEMENT => 22;
2020

21+
use constant CODE_SNIPPET => 30;
22+
use constant CODE_SNIPPET_CPP => 31;
23+
2124
# read arguments
2225
my $debug = 0;
2326
die("usage: $0 [-debug] headerfile\n") unless GetOptions ("debug" => \$debug) && @ARGV == 1;
@@ -121,19 +124,26 @@ sub write_header_footer {
121124
sub processDoxygenLine {
122125
my $line = $_[0];
123126

124-
# detect code snipped
125-
if ( $line =~ m/\\code\{\.(\w+)\}/ ) {
126-
my $codelang = $1;
127+
# detect code snippet
128+
if ( $line =~ m/\\code(\{\.(\w+)\})?/ ) {
129+
my $codelang = "";
130+
$codelang = " $2" if (defined $2);
131+
$CODE_SNIPPET = CODE_SNIPPET;
132+
$CODE_SNIPPET = CODE_SNIPPET_CPP if ($codelang =~ m/cpp/ );
127133
$codelang =~ s/py/python/;
128-
$CODE_SNIPPET=1;
129-
return ".. code-block:: $codelang\n\n";
134+
return "\n" if ( $CODE_SNIPPET == CODE_SNIPPET_CPP );
135+
return ".. code-block::$codelang\n\n";
130136
}
131137
if ( $line =~ m/\\endcode/ ) {
132138
$CODE_SNIPPET = 0;
133139
return "\n";
134140
}
135-
if ($CODE_SNIPPET == 1){
136-
return " $line\n";
141+
if ($CODE_SNIPPET != 0){
142+
if ( $CODE_SNIPPET == CODE_SNIPPET_CPP ){
143+
return "";
144+
} else {
145+
return " $line\n";
146+
}
137147
}
138148

139149
# remove prepending spaces
@@ -181,7 +191,7 @@ sub processDoxygenLine {
181191
}
182192
# create links in plain text too (less performant)
183193
if ( $line =~ m/\b(Qgs[A-Z]\w+)\b(\.?$|[^\w]{2})/) {
184-
if ( $1 !~ $ACTUAL_CLASS ) {
194+
if ( defined $ACTUAL_CLASS && $1 !~ $ACTUAL_CLASS ) {
185195
$line =~ s/\b(Qgs[A-Z]\w+)\b(\.?$|[^\w]{2})/:py:class:`$1`$2/g;
186196
}
187197
}

0 commit comments

Comments
 (0)