Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
1.9 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. #!/usr/bin/perl
  2. package Display::LaTeX;
  3. use strict;
  4. use warnings;
  5. no warnings 'uninitialized';
  6. use Exporter;
  7. our @ISA = qw(Exporter);
  8. our %EXPORT_TAGS = ( 'all' => [ qw(a div p em small strong table
  9. table_row table_cell entry_markup
  10. heading) ],
  11. 'highlevel' => [ qw(a p em small strong table
  12. table_row table_cell
  13. entry_markup heading) ] );
  14. our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
  15. our @EXPORT = qw( );
  16. # Generate subs for these:
  17. my %tags = (
  18. p => \&escape,
  19. textbf => \&tag,
  20. em => \&tag,
  21. small => \&tag,
  22. strong => \&tag,
  23. table => \&environment,
  24. tr => \&tag,
  25. td => \&tag,
  26. a => \&tag,
  27. div => \&tag,
  28. );
  29. # ...but map these tags to different sub names:
  30. my %tagmap = (
  31. textbf => 'strong',
  32. );
  33. # Install appropriate subs in symbol table:
  34. { no strict 'refs';
  35. for my $key (keys %tags) {
  36. my $subname = $tagmap{$key};
  37. $subname = $key unless ($subname);
  38. *{ $subname } = sub { $tags{$key}->($key, @_); };
  39. }
  40. }
  41. # handle most HTML tags:
  42. sub tag {
  43. my ($tag) = shift;
  44. my (@params) = @_;
  45. my ($attr_string, $text);
  46. for my $param (@params) {
  47. if ($param =~ m/^([a-z]+): ?(.*)$/) {
  48. my ($name, $value) = ($1, $2);
  49. $attr_string .= qq{ $name="$value"}
  50. }
  51. else {
  52. $text .= "\n" if length($text) > 0;
  53. $text .= $param;
  54. }
  55. }
  56. # voila, an X(HT)ML tag:
  57. return "\\${tag}\{$text\}";
  58. }
  59. sub environment {
  60. my ($name) = shift;
  61. }
  62. sub escape {
  63. shift;
  64. return @_;
  65. }
  66. ########################################
  67. # Special cases and higher-level markup
  68. sub entry_markup {
  69. my ($text) = @_;
  70. return div($text, 'class: entry') . "\n";
  71. }
  72. sub heading {
  73. my ($text, $level) = @_;
  74. my $h = "h$level";
  75. return tag($h, $text);
  76. }
  77. 1;