[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
@U attempt
From: |
Karl Berry |
Subject: |
@U attempt |
Date: |
Sun, 8 Feb 2015 22:37:00 GMT |
So, I attempted to implement @U (didn't do the user documentation or
tests yet). What I did seems to get the right output, but I confess I'm
not at all sure I did the right thing -- especially to get the text of
the argument. I read the pod docs that I could find, but probably
missed some crucial stuff; the elements of the overall tree+list data
structure remain opaque to me, I'm afraid. Patrice, if you wrote up
some overall documentation about that, please send a pointer.
Also, I just assumed the arg would be literal hex digits, that is, not
supporting things like @address@hidden or @address@hidden I
know the code could easily handle such, but I felt like enough time had
passed already without delving into that.
Below are the important diffs (not in applyable form; I committed the
actual changes). Patrice, if you could give it a quick look, that would
be greatly appreciated. If I'm totally on the wrong track, just say so,
and I'll revert it and we won't have @U in the forthcoming release. Not
the end of the world.
Thanks,
Karl
--- tp/Texinfo/Common.pm (revision 6107)
+++ tp/Texinfo/Common.pm (working copy)
@@ -599,9 +602,8 @@
-foreach my $one_arg_command (
- 'ctrl','dmn', 'w', 'key',
- 'titlefont','hyphenation','anchor','errormsg') {
+foreach my $one_arg_command ('U', 'ctrl', 'dmn', 'w', 'key',
+ 'titlefont', 'hyphenation', 'anchor', 'errormsg') {
$brace_commands{$one_arg_command} = 1;
}
--- tp/Texinfo/Parser.pm (revision 6107)
+++ tp/Texinfo/Parser.pm (working copy)
@@ -436,10 +437,10 @@
-foreach my $command ('titlefont', 'anchor', 'xref','ref','pxref',
+foreach my $command ('titlefont', 'anchor', 'xref','ref', 'pxref',
'inforef', 'shortcaption', 'math', 'indicateurl',
'email', 'uref', 'url', 'image', 'abbr', 'acronym',
- 'dmn', 'ctrl', 'errormsg') {
+ 'dmn', 'ctrl', 'errormsg', 'U') {
$simple_text_commands{$command} = 1;
}
--- tp/Texinfo/Convert/HTML.pm (revision 6107)
+++ tp/Texinfo/Convert/HTML.pm (working copy)
@@ -1831,9 +1831,36 @@
+sub _convert_U_command($$$$)
+{
+ my $self = shift;
+ my $cmdname = shift;
+ my $command = shift;
+ my $args = shift;
+ my $res;
+
+ my $text = $args->[0]->{'normal'};
+ # these tests should be in the parser; duplicated in Plaintext.pm
+ if (!defined($text) || !$text) {
+ $self->line_warn($self->__("no argument specified for address@hidden"),
+ $command->{'line_nr'});
+ $res = '';
+
+ } elsif ($text !~ /^[0-9A-Fa-f]+$/) {
+ $self->line_error(
+ sprintf($self->__("non-hex digits in argument for address@hidden: %s"),
$text),
+ $command->{'line_nr'});
+ $res = '';
+
+ } else {
+ $res = "&#x$text;"; # ok
+ }
+ return $res;
+}
+$default_commands_conversion{'U'} = \&_convert_U_command;
+
sub _default_comment($$) {
my $self = shift;
my $text = shift;
--- tp/Texinfo/Convert/Plaintext.pm (revision 6107)
+++ tp/Texinfo/Convert/Plaintext.pm (working copy)
@@ -2185,6 +2186,32 @@
$self->_add_text_count($result);
$self->_add_lines_count(2);
return $result;
+
+ } elsif ($command eq 'U') {
+ my $arg = $root->{'extra'}->{'brace_command_contents'}
+ ->[0]->[0]->{'text'};
+ my $res;
+ # these tests should be in the parser; duplicated in HTML.pm
+ if (!defined($arg) || !$arg) {
+ $self->line_warn($self->__("no argument specified for address@hidden"),
+ $root->{'line_nr'});
+ $res = '';
+
+ } elsif ($arg !~ /^[0-9A-Fa-f]+$/) {
+ $self->line_error(
+ sprintf($self->__("non-hex digits in argument for address@hidden:
%s"), $arg),
+ $root->{'line_nr'});
+ $res = '';
+
+ } else {
+ # binary if utf-8 being output, else ascii.
+ $res = $self->{'to_utf8'} ? chr(hex($arg)) : "U+$arg";
+ }
+
+ $result .= $self->_count_added($formatter->{'container'},
+ $formatter->{'container'}->add_text($res, $res));
+ return $result;
+
} elsif ($command eq 'value') {
my $expansion = $self->gdt('@{No value for `{value}\'@}',
{'value' => $root->{'type'}});
--- tp/Texinfo/Convert/DocBook.pm (revision 6107)
+++ tp/Texinfo/Convert/DocBook.pm (working copy)
@@ -1069,6 +1072,19 @@
} else {
return '';
}
+
+ } elsif ($root->{'cmdname'} eq 'U') {
+ my $argument = $root->{'extra'}->{'brace_command_contents'}->[0]
+ ->[0]->{'text'};
+ if (defined($argument) && $argument) {
+ $result = "&#x$argument;";
+ } else {
+ $self->line_warn($self->__("no argument specified for
address@hidden"),
+ $root->{'line_nr'});
+ $result = '';
+ }
+ return $result;
+
} elsif ($Texinfo::Common::inline_commands{$root->{'cmdname'}}) {
my $expand = 0;
if ($Texinfo::Common::inline_format_commands{$root->{'cmdname'}}) {
- @U attempt,
Karl Berry <=