Bug 919474 - RFE: Ability to use case-insensitive "language" attributes on programlistings for compatibility with other docbook projects.
Summary: RFE: Ability to use case-insensitive "language" attributes on programlistings...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Publican
Classification: Community
Component: publican
Version: 3.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: 3.2
Assignee: Jeff Fearn 🐞
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks: 913281
TreeView+ depends on / blocked
 
Reported: 2013-03-08 15:29 UTC by Stephen Gordon
Modified: 2013-11-29 00:35 UTC (History)
4 users (show)

Fixed In Version: 3.2.0
Clone Of:
Environment:
Last Closed: 2013-11-29 00:35:04 UTC
Embargoed:


Attachments (Terms of Use)
XSLT to convert programlisting language to value recognized by Kate.pm (17.04 KB, application/xml)
2013-04-17 19:57 UTC, Stephen Gordon
no flags Details

Description Stephen Gordon 2013-03-08 15:29:52 UTC
Description of problem:

I have been working of late to see how feasible it is to build documentation from the openstack-manuals project using Publican, allowing us to single source while working with the upstream community. At this time I am looking at using a pre-build script to perform some transformations on the XML to allow this but some of these seem like they should/could be unnecessary.

One of these is that the build system used upstream copes with lower case language attribute values on programlisting elements, so for example this is widespread in the source:

<programlisting language="bash">

This causes a fatal error when built with publican (Kate.pm expects "Bash") but works with other build systems including the one used to produce docs.openstack.org (clouddocs-maven). The DocBook specification only states that the language attribute must be CDATA.

Currently what I am doing in my pre-build scripting is to replace these with the values publican expects, but ideally what I would like to see - and what I am requesting under this bug - is some mapping 

Assuming that the highlighting functionality built/used by Kate is unlikely to change in this respect I would like to see some translation at the publican level of languages attributes - irrespective of case - to those expected by Kate.pm.

Version-Release number of selected component (if applicable):

publican-3.1.3-1.fc17.noarch

Comment 1 Stephen Gordon 2013-04-17 19:57:12 UTC
Created attachment 737001 [details]
XSLT to convert programlisting language to value recognized by Kate.pm

I have attached XSLT which converts all programlisting language attributes to the values recognized by Kate.pm, assuming that the only difference between the source value and a recognized value is the case. Source values are checked against all values listed as supported by Kate.pm. If the language attribute is not recognized at all then it is left "as is" (source).

Comment 2 Jeff Fearn 🐞 2013-04-18 03:02:14 UTC
This might be better as a patch to the highlighting module.

--- a/Syntax/Highlight/Engine/Kate.pm	2010-01-23 06:39:05.000000000 +1000
+++ b/Syntax/Highlight/Engine/Kate.pm	2013-04-18 12:51:36.929757998 +1000
@@ -610,10 +610,28 @@
 }
 
 sub languagePlug {
-	my ($self, $req) = @_;
+	my ($self, $req, $insensitive) = @_;
+
 	unless (exists($self->{'syntaxes'}->{$req})) {
-		warn "undefined language: $req";
-		return undef;
+		if(defined($insensitive) && $insensitive) {
+			my $matched = 0;
+			foreach my $key () {
+				if($key =~ /^$req$/i){
+					warn "substituting language $key for $req";
+					$req = $key;
+					$matched = 1;
+					last;
+				}
+			}
+
+			unless ($matched) {
+				warn "undefined language: $req";
+				return undef;
+			}
+		} else {
+			warn "undefined language: $req";
+			return undef;
+		}


Then we supply the extra parameter in publican and away we go.

Comment 3 Jeff Fearn 🐞 2013-04-18 03:05:06 UTC
gah

-foreach my $key () {
+foreach my $key (keys(%{$self->{'syntaxes'}})) {

Comment 4 Jeff Fearn 🐞 2013-05-02 02:04:34 UTC
FYI I have opened an upstream bug to get this added to the highlighting module.

https://rt.cpan.org/Ticket/Display.html?id=84982

I'm happy to carry this patch in perl-Syntax-Highlight-Engine-Kate internally until it gets upstream. You will need to contact the Fedora package maintainer if you'd like them to carry the patch.

Once the patch is in place there are a couple of small changes we need to make to publican to switch on the new behavior.

A: bump the module dep in Build.pm to match the new version of the highlighting module

B: this patch to Builder.pm

 @@ -2314,7 +2314,7 @@
         },
     );
 
-    my $tmp = $hl->languagePlug($language) || croak(
+    $language = $hl->languagePlug($language) || croak(

C: communicate the patch requirement to maintainers on other distros.

Comment 5 Jeff Fearn 🐞 2013-05-02 02:05:56 UTC
sigh moar coffee

B: this patch to Builder.pm

 @@ -2314,7 +2314,7 @@
         },
     );
 
-    my $tmp = $hl->languagePlug($language) || croak(
+    $language = $hl->languagePlug($language, 1) || croak(

Comment 6 HSS Product Manager 2013-07-09 08:17:33 UTC
HSS-QE has reviewed and declined this request. QE for this bug will be handled by IED.

Comment 7 Jeff Fearn 🐞 2013-07-09 22:56:26 UTC
To ssh://git.fedorahosted.org/git/publican.git
   bcea0b5..0dec188  HEAD -> devel

Comment 8 Petr Bokoc 2013-07-22 15:41:27 UTC
The language attribute on programlistings is now case-insensitive.

I ran into a small related issue; I filed a separate bug (BZ#987059) so that it doesn't block this.

Verified in publican-3.1.5-0.fc17.t62.noarch.

Comment 9 Jeff Fearn 🐞 2013-08-09 04:48:40 UTC
The fix for this bug has been shipped in publican 3.2.0

Comment 10 Ruediger Landmann 2013-11-25 18:09:14 UTC
There seems to be a regression in publican-3.9.9-0.fc19.t28.noarch:

Starting html
        Using XML::LibXSLT on /usr/share/publican/xsl/html.xsl
undefined language: xml at /usr/share/perl5/vendor_perl/Syntax/Highlight/Engine/Kate.pm line 621.
LibXSLT: error coming back from perl-dispatcher in pm file. 
        'xml' is not a valid language for highlighting.
 at /usr/lib64/perl5/vendor_perl/XML/LibXSLT.pm line 81.

Changing 

<programlisting language="xml"> 

to

<programlisting language="XML"> 

lets the book build fine

Comment 11 Jeff Fearn 🐞 2013-11-25 22:16:59 UTC
I've updated the PUG so that one of the programlistings uses "xml".

substituting language XML for xml at /usr/share/perl5/vendor_perl/Syntax/Highlight/Engine/Kate.pm line 626.

Works for me.

Comment 12 Ruediger Landmann 2013-11-29 00:35:04 UTC
Thanks Jeff; looks like I had an out-of-date dep here.


Note You need to log in before you can comment on or make changes to this bug.