[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Customization of uppercasing commands
From: |
Patrice Dumas |
Subject: |
branch master updated: Customization of uppercasing commands |
Date: |
Wed, 15 Nov 2023 06:04:13 -0500 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new b3c1708347 Customization of uppercasing commands
b3c1708347 is described below
commit b3c1708347010780e5145063a7fa13461ebf29e3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Nov 15 12:04:06 2023 +0100
Customization of uppercasing commands
* doc/texi2any_api.texi (Customization of Commands Converting to
Uppercase), tp/Texinfo/Config.pm ($GNUT_upper_case_commands)
(texinfo_register_upper_case_command)
(GNUT_get_upper_case_commands_info, GNUT_reinitialize_init_files),
tp/Texinfo/Convert/HTML.pm (%default_upper_case_commands)
(converter_initialize, _convert), tp/Texinfo/XS/convert/convert_html.c
(html_format_init, convert_to_html_internal),
tp/Texinfo/XS/convert/get_html_perl_info.c
(html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
(CONVERTER): add possibility of customizing commands converting their
argument to uppercase letters.
---
ChangeLog | 16 ++++++++++++++++
doc/texi2any_api.texi | 25 +++++++++++++++++++++++++
tp/TODO | 2 ++
tp/Texinfo/Config.pm | 24 +++++++++++++++++++++++-
tp/Texinfo/Convert/HTML.pm | 22 +++++++++++++++++-----
tp/Texinfo/XS/convert/convert_html.c | 12 +++++-------
tp/Texinfo/XS/convert/get_html_perl_info.c | 29 +++++++++++++++++++++++++++++
tp/Texinfo/XS/main/converter_types.h | 1 +
8 files changed, 118 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 059d8491e7..69500614a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-11-15 Patrice Dumas <pertusus@free.fr>
+
+ Customization of uppercasing commands
+
+ * doc/texi2any_api.texi (Customization of Commands Converting to
+ Uppercase), tp/Texinfo/Config.pm ($GNUT_upper_case_commands)
+ (texinfo_register_upper_case_command)
+ (GNUT_get_upper_case_commands_info, GNUT_reinitialize_init_files),
+ tp/Texinfo/Convert/HTML.pm (%default_upper_case_commands)
+ (converter_initialize, _convert), tp/Texinfo/XS/convert/convert_html.c
+ (html_format_init, convert_to_html_internal),
+ tp/Texinfo/XS/convert/get_html_perl_info.c
+ (html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
+ (CONVERTER): add possibility of customizing commands converting their
+ argument to uppercase letters.
+
2023-11-15 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/converter.h (OTXI_PROTECT_XML_CASES),
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index f7bc58f115..44ff7a68ab 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -538,6 +538,31 @@ customization of translated strings.
@node Simple Customization for Simple Commands with Braces
@section Simple Customization for Simple Commands with Braces
+@node Customization of Commands Converting to Uppercase
+@subsection Customization of Commands Converting to Uppercase
+
+@cindex HTML determine commands converting to uppercase
+
+Formatting of @code{@@sc} may involve uppercasing the argument.
+The specification of @@-command argument uppercasing can be changed with
+@code{texinfo_register_upper_case_command}:
+
+@defun texinfo_register_upper_case_command ($command_name, $value)
+@var{$command_name} is the @@-command name, without the leading @@.
+@var{$value} sets or unsets uppercasing of argument.
+@end defun
+
+For example, to prevent @code{@@sc} argument from being upper-cased and set
+@code{@@var} argument to be uppercased:
+
+@example
+texinfo_register_upper_case_command('sc', 0);
+texinfo_register_upper_case_command('var', 1);
+@end example
+
+@node Simple Output Customization for Simple Commands with Braces
+@subsection Simple Output Customization for Simple Commands with Braces
+
@cindex HTML customization for simple commands
@cindex Simple commands, customizing HTML for
@cindex Style commands, customizing HTML for
diff --git a/tp/TODO b/tp/TODO
index 8a3bc510ae..a7b423a4fb 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -10,6 +10,8 @@ This is the todo list for texi2any
Before next release
===================
+ 'span.sc' => 'font-variant: small-caps',
+
check $(native_tools) variable in Makefile.am does not seems to be
set and seems useless.
diff --git a/tp/Texinfo/Config.pm b/tp/Texinfo/Config.pm
index 31b2679885..10eea33d26 100644
--- a/tp/Texinfo/Config.pm
+++ b/tp/Texinfo/Config.pm
@@ -425,6 +425,7 @@ my $GNUT_commands_open = {};
my $GNUT_output_units_conversion = {};
my $GNUT_types_conversion = {};
my $GNUT_types_open = {};
+my $GNUT_upper_case_commands = {};
my $GNUT_no_arg_commands_formatting_strings = {};
my $GNUT_style_commands_formatting_info = {};
my $GNUT_accent_command_formatting_info = {};
@@ -584,7 +585,8 @@ _GNUT_initialize_special_unit_info();
# $translated_converted_string is supposed to be already formatted.
# It may also be relevant to be able to pass a 'tree'
-# directly (it is actually handled by the converter code).
+# directly (it is actually handled by the converter code in perl, probably
+# not with XS).
sub texinfo_register_no_arg_command_formatting($$;$$$$)
{
my $command = shift;
@@ -689,6 +691,25 @@ sub GNUT_get_style_command_formatting($;$)
return undef;
}
+# called from init files
+sub texinfo_register_upper_case_command($$)
+{
+ my $command = shift;
+ my $value = shift;
+
+ if ($value) {
+ $GNUT_upper_case_commands->{$command} = 1;
+ } else {
+ $GNUT_upper_case_commands->{$command} = 0;
+ }
+}
+
+# called from the Converter
+sub GNUT_get_upper_case_commands_info()
+{
+ return $GNUT_upper_case_commands;
+}
+
# called from init files
sub texinfo_register_accent_command_formatting($$$)
{
@@ -793,6 +814,7 @@ sub GNUT_reinitialize_init_files()
foreach my $reference ($init_files_options,
$GNUT_file_id_setting_references,
$GNUT_formatting_references, $GNUT_formatting_special_unit_body,
+ $GNUT_upper_case_commands,
$GNUT_commands_conversion, $GNUT_commands_open, $GNUT_types_conversion,
$GNUT_types_open, $GNUT_accent_command_formatting_info,
$GNUT_types_formatting_info, $GNUT_direction_string_info) {
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index d4801b32ef..481a990022 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -209,9 +209,6 @@ foreach my $block_command (keys(%block_commands)) {
if ($block_commands{$block_command} eq 'format_raw');
}
-# FIXME allow customization? (also in DocBook)
-my %upper_case_commands = ( 'sc' => 1 );
-
# API for html formatting
@@ -2890,6 +2887,8 @@ foreach my $quoted_command ('samp') {
$quoted_style_commands{$quoted_command} = 1;
}
+my %default_upper_case_commands = ( 'sc' => 1 );
+
my %style_commands_element = (
'b' => 'b',
'cite' => 'cite',
@@ -8238,6 +8237,19 @@ sub converter_initialize($)
= $customized_type_formatting->{$type}->{'pre_class'};
}
+ $self->{'upper_case_commands'} = {};
+ foreach my $command (keys(%default_upper_case_commands)) {
+ $self->{'upper_case_commands'}->{$command}
+ = $default_upper_case_commands{$command};
+ }
+ my $customized_upper_case_commands
+ = Texinfo::Config::GNUT_get_upper_case_commands_info();
+ foreach my $command (keys(%$customized_upper_case_commands)) {
+ $self->{'upper_case_commands'}->{$command}
+ = $customized_upper_case_commands->{$command};
+ }
+
+
$self->{'commands_conversion'} = {};
my $customized_commands_conversion
= Texinfo::Config::GNUT_get_commands_conversion();
@@ -12183,7 +12195,7 @@ sub _convert($$;$)
} elsif ($brace_commands{$command_name}
and $brace_commands{$command_name} eq 'style_no_code') {
push @{$self->{'document_context'}->[-1]->{'monospace'}}, 0;
- } elsif ($upper_case_commands{$command_name}) {
+ } elsif ($self->{'upper_case_commands'}->{$command_name}) {
$self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
->{'upper_case'}++;
} elsif ($math_commands{$command_name}) {
@@ -12315,7 +12327,7 @@ sub _convert($$;$)
and $brace_commands{$command_name} eq 'style_no_code')
or $brace_code_commands{$command_name}) {
pop @{$self->{'document_context'}->[-1]->{'monospace'}};
- } elsif ($upper_case_commands{$command_name}) {
+ } elsif ($self->{'upper_case_commands'}->{$command_name}) {
$self->{'document_context'}->[-1]->{'formatting_context'}->[-1]
->{'upper_case'}--;
} elsif ($math_commands{$command_name}) {
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 958ee64405..e1e798a182 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -117,7 +117,9 @@ CMD_VARIETY command_special_unit_variety[] = {
#define HF_format_context 0x0002
#define HF_format_raw 0x0004
#define HF_pre_class 0x0008
-#define HF_upper_case 0x0010
+/*
+#define HF_ 0x0010
+ */
#define HF_HTML_align 0x0020
#define HF_special_variety 0x0040
@@ -2651,8 +2653,6 @@ html_format_init ()
}
html_commands_data[CM_float].flags |= HF_composition_context;
-
- html_commands_data[CM_sc].flags |= HF_upper_case;
}
/* most of the initialization is done by html_converter_initialize_sv
@@ -2704,8 +2704,6 @@ html_converter_initialize (CONVERTER *self)
self->command_special_variety_name_index[i].cmd = cmd;
self->command_special_variety_name_index[i].index = number - 1;
}
-
-
}
void
@@ -3510,7 +3508,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT
*element,
push_style_no_code (&top_document_ctx->monospace);
self->modified_state |= HMSF_monospace;
}
- else if (html_commands_data[data_cmd].flags & HF_upper_case)
+ else if (self->upper_case[cmd])
{
top_formating_ctx->upper_case_ctx++;
self->modified_state |= HMSF_top_formatting_context;
@@ -3799,7 +3797,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT
*element,
pop_monospace_context (&top_document_ctx->monospace);
self->modified_state |= HMSF_monospace;
}
- else if (html_commands_data[data_cmd].flags & HF_upper_case)
+ else if (self->upper_case[cmd])
{
top_formating_ctx->upper_case_ctx--;
self->modified_state |= HMSF_top_formatting_context;
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 4abb0a2f09..f8217abc79 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -149,6 +149,7 @@ html_converter_initialize_sv (SV *converter_sv,
SV **commands_conversion_sv;
SV **output_units_conversion_sv;
SV **code_types_sv;
+ SV **upper_case_commands_sv;
SV **pre_class_types_sv;
HV *formatting_function_hv;
HV *commands_open_hv;
@@ -515,6 +516,34 @@ html_converter_initialize_sv (SV *converter_sv,
}
}
+ FETCH(upper_case_commands)
+
+ if (upper_case_commands_sv)
+ {
+ I32 hv_number;
+ I32 i;
+
+ HV *upper_case_commands_hv = (HV *)SvRV (*upper_case_commands_sv);
+
+ hv_number = hv_iterinit (upper_case_commands_hv);
+
+ for (i = 0; i < hv_number; i++)
+ {
+ I32 retlen;
+ char *cmdname;
+ SV *upper_case_sv = hv_iternextsv (upper_case_commands_hv,
+ &cmdname, &retlen);
+ if (SvOK (upper_case_sv))
+ {
+ int upper_case_value = SvIV (upper_case_sv);
+ enum command_id cmd = lookup_builtin_command (cmdname);
+ if (!cmd)
+ fprintf (stderr, "ERROR: %s: no upper-case command\n",
cmdname);
+ else
+ converter->upper_case[cmd] = upper_case_value;
+ }
+ }
+ }
FETCH(no_arg_commands_formatting)
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 3b3cd3537a..bc62a9a3e3 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -364,6 +364,7 @@ typedef struct CONVERTER {
COMMAND_ID_LIST no_arg_formatted_cmd;
int code_types[ET_special_unit_element+1];
char *pre_class_types[ET_special_unit_element+1];
+ int upper_case[BUILTIN_CMD_NUMBER];
FORMATTING_REFERENCE
formatting_references[FR_format_translate_message+1];
FORMATTING_REFERENCE
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Customization of uppercasing commands,
Patrice Dumas <=