-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To attribute #2465
To attribute #2465
Changes from 5 commits
a82a3ec
7e95d22
7d2ae5c
2edb87b
ff55b73
f05321b
6dcbbb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,31 @@ sub beAbsorbed { | |
LaTeXML::Core::Definition::stopProfiling($profiled, 'absorb') if $profiled; | ||
return @result; } | ||
|
||
# Similar to ->revert, but converts to pure string for use in an attribute value | ||
sub toAttribute { | ||
my ($self) = @_; | ||
my $props = $$self{properties}; | ||
my $defn = $self->getDefinition; | ||
my $spec = $$props{toAttribute} || $$defn{toAttribute}; | ||
if (!defined $spec) { | ||
return $self->toString; } # Default | ||
elsif (ref $spec eq 'CODE') { # If handled by CODE, call it | ||
$spec = &$spec($self, $self->getArgs); } | ||
# Now, similar to substituteParameters, but creating a string. | ||
$spec =~ s/#(#|[1-9]|\w+)/ toAttribute_aux($self,$1)/eg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I think I understand the code here, but I am wondering if we should have a an example DefConstructor that uses this argument-based There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conceit is that it should work just like |
||
return $spec; } | ||
|
||
sub toAttribute_aux { | ||
my ($self, $code) = @_; | ||
my $value; | ||
if ($code eq '#') { return $code; } | ||
elsif ((ord($code) > ord('0')) && (ord($code) <= ord('9'))) { | ||
$value = $self->getArg(ord($code) - ord('0')); } | ||
else { | ||
$value = $self->getProperty($code); } | ||
$value = $value->toAttribute if (defined $value) && (ref $value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed; fixed. |
||
return $value; } | ||
|
||
# See discussion in Box.pm | ||
sub computeSize { | ||
my ($self, %options) = @_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1383,7 +1383,7 @@ sub flatten { | |
my $constructor_options = { # [CONSTANT] | ||
mode => 1, requireMath => 1, forbidMath => 1, font => 1, | ||
alias => 1, reversion => 1, sizer => 1, properties => 1, | ||
nargs => 1, | ||
nargs => 1, toAttribute => 1, | ||
beforeDigest => 1, afterDigest => 1, beforeConstruct => 1, afterConstruct => 1, | ||
captureBody => 1, scope => 1, bounded => 1, locked => 1, | ||
outer => 1, long => 1, robust => 1 }; | ||
|
@@ -1425,6 +1425,7 @@ sub DefConstructorI { | |
alias => (defined $options{alias} ? $options{alias} | ||
: ($options{robust} ? $cs : undef)), | ||
reversion => $options{reversion}, | ||
toAttribute => $options{toAttribute}, | ||
sizer => inferSizer($options{sizer}, $options{reversion}), | ||
captureBody => $options{captureBody}, | ||
properties => $options{properties} || {}, | ||
|
@@ -1827,7 +1828,8 @@ my $environment_options = { # [CONSTANT] | |
beforeDigest => 1, afterDigest => 1, | ||
afterDigestBegin => 1, beforeDigestEnd => 1, afterDigestBody => 1, | ||
beforeConstruct => 1, afterConstruct => 1, | ||
reversion => 1, sizer => 1, scope => 1, locked => 1 }; | ||
reversion => 1, sizer => 1, scope => 1, locked => 1, | ||
toAttribute => 1 }; | ||
|
||
sub DefEnvironment { | ||
my ($proto, $replacement, %options) = @_; | ||
|
@@ -1873,8 +1875,9 @@ sub DefEnvironmentI { | |
nargs => $options{nargs}, | ||
captureBody => 1, | ||
properties => $options{properties} || {}, | ||
(defined $options{reversion} ? (reversion => $options{reversion}) : ()), | ||
(defined $sizer ? (sizer => $sizer) : ()), | ||
(defined $options{reversion} ? (reversion => $options{reversion}) : ()), | ||
(defined $options{toAttribute} ? (toAttribute => $options{toAttribute}) : ()), | ||
(defined $sizer ? (sizer => $sizer) : ()), | ||
), $options{scope}); | ||
$STATE->installDefinition(LaTeXML::Core::Definition::Constructor | ||
->new(T_CS("\\end{$name}"), "", "", | ||
|
@@ -1914,8 +1917,9 @@ sub DefEnvironmentI { | |
nargs => $options{nargs}, | ||
captureBody => T_CS("\\end$name"), # Required to capture!! | ||
properties => $options{properties} || {}, | ||
(defined $options{reversion} ? (reversion => $options{reversion}) : ()), | ||
(defined $sizer ? (sizer => $sizer) : ()), | ||
(defined $options{reversion} ? (reversion => $options{reversion}) : ()), | ||
(defined $options{toAttribute} ? (toAttribute => $options{toAttribute}) : ()), | ||
(defined $sizer ? (sizer => $sizer) : ()), | ||
), $options{scope}); | ||
$STATE->installDefinition(LaTeXML::Core::Definition::Constructor | ||
->new(T_CS("\\end$name"), "", "", | ||
|
@@ -3682,6 +3686,14 @@ the one defined in the C<prototype>. This is a convenient alternative for | |
reversion when a 'public' command conditionally expands into | ||
an internal one, but the reversion should be for the public command. | ||
|
||
=item C<toAttribute=E<gt>I<texstring> | I<code>($whatsit,#1,#2,...)> | ||
|
||
specifies the conversion of the invocation back into plain text for an attribute value | ||
(the default is C<toString>). | ||
The I<textstring> string can include C<#1>, C<#2>... | ||
The I<code> is called with the C<$whatsit> and digested arguments | ||
and must return a string. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly a doc string like this is also needed for the DefEnvironment addition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, done. |
||
|
||
=item C<sizer=E<gt>I<string> | I<code>($whatsit)> | ||
|
||
specifies how to compute (approximate) the displayed size of the object, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to emit a
Warning
if this unusual case is encountered, where$value
was e.g. a perl array ref or hash ref? Could be some rare mistake that gets caught quickly with a warning message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea; done!