Tome

Hex Artifact Content
Login

Artifact 966e7d983bd7174e2505b9f693fe93e1a4a794de94addcbaad710e24a7088c87:


0000: 2f 2f 20 43 6f 70 79 72 69 67 68 74 20 28 43 29  // Copyright (C)
0010: 20 44 61 76 69 64 20 4e 2e 20 43 6f 68 65 6e 0a   David N. Cohen.
0020: 0a 2f 2f 20 54 68 69 73 20 70 72 6f 67 72 61 6d  .// This program
0030: 20 69 73 20 66 72 65 65 20 73 6f 66 74 77 61 72   is free softwar
0040: 65 3a 20 79 6f 75 20 63 61 6e 20 72 65 64 69 73  e: you can redis
0050: 74 72 69 62 75 74 65 20 69 74 20 61 6e 64 2f 6f  tribute it and/o
0060: 72 20 6d 6f 64 69 66 79 0a 2f 2f 20 69 74 20 75  r modify.// it u
0070: 6e 64 65 72 20 74 68 65 20 74 65 72 6d 73 20 6f  nder the terms o
0080: 66 20 74 68 65 20 47 4e 55 20 41 66 66 65 72 6f  f the GNU Affero
0090: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 20   General Public 
00a0: 4c 69 63 65 6e 73 65 20 61 73 20 70 75 62 6c 69  License as publi
00b0: 73 68 65 64 20 62 79 0a 2f 2f 20 74 68 65 20 46  shed by.// the F
00c0: 72 65 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75  ree Software Fou
00d0: 6e 64 61 74 69 6f 6e 2c 20 65 69 74 68 65 72 20  ndation, either 
00e0: 76 65 72 73 69 6f 6e 20 33 20 6f 66 20 74 68 65  version 3 of the
00f0: 20 4c 69 63 65 6e 73 65 2c 20 6f 72 0a 2f 2f 20   License, or.// 
0100: 28 61 74 20 79 6f 75 72 20 6f 70 74 69 6f 6e 29  (at your option)
0110: 20 61 6e 79 20 6c 61 74 65 72 20 76 65 72 73 69   any later versi
0120: 6f 6e 2e 0a 0a 2f 2f 20 54 68 69 73 20 70 72 6f  on...// This pro
0130: 67 72 61 6d 20 69 73 20 64 69 73 74 72 69 62 75  gram is distribu
0140: 74 65 64 20 69 6e 20 74 68 65 20 68 6f 70 65 20  ted in the hope 
0150: 74 68 61 74 20 69 74 20 77 69 6c 6c 20 62 65 20  that it will be 
0160: 75 73 65 66 75 6c 2c 0a 2f 2f 20 62 75 74 20 57  useful,.// but W
0170: 49 54 48 4f 55 54 20 41 4e 59 20 57 41 52 52 41  ITHOUT ANY WARRA
0180: 4e 54 59 3b 20 77 69 74 68 6f 75 74 20 65 76 65  NTY; without eve
0190: 6e 20 74 68 65 20 69 6d 70 6c 69 65 64 20 77 61  n the implied wa
01a0: 72 72 61 6e 74 79 20 6f 66 0a 2f 2f 20 4d 45 52  rranty of.// MER
01b0: 43 48 41 4e 54 41 42 49 4c 49 54 59 20 6f 72 20  CHANTABILITY or 
01c0: 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20 50 41  FITNESS FOR A PA
01d0: 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f 53 45  RTICULAR PURPOSE
01e0: 2e 20 20 53 65 65 20 74 68 65 0a 2f 2f 20 47 4e  .  See the.// GN
01f0: 55 20 41 66 66 65 72 6f 20 47 65 6e 65 72 61 6c  U Affero General
0200: 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20   Public License 
0210: 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73  for more details
0220: 2e 0a 0a 2f 2f 20 59 6f 75 20 73 68 6f 75 6c 64  ...// You should
0230: 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 61   have received a
0240: 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e 55   copy of the GNU
0250: 20 41 66 66 65 72 6f 20 47 65 6e 65 72 61 6c 20   Affero General 
0260: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 0a 2f  Public License./
0270: 2f 20 61 6c 6f 6e 67 20 77 69 74 68 20 74 68 69  / along with thi
0280: 73 20 70 72 6f 67 72 61 6d 2e 20 20 49 66 20 6e  s program.  If n
0290: 6f 74 2c 20 73 65 65 20 3c 68 74 74 70 73 3a 2f  ot, see <https:/
02a0: 2f 77 77 77 2e 67 6e 75 2e 6f 72 67 2f 6c 69 63  /www.gnu.org/lic
02b0: 65 6e 73 65 73 2f 3e 2e 0a 0a 70 61 63 6b 61 67  enses/>...packag
02c0: 65 20 6d 61 69 6e 0a 0a 69 6d 70 6f 72 74 20 28  e main..import (
02d0: 0a 09 22 65 72 72 6f 72 73 22 0a 09 22 66 6c 61  .."errors".."fla
02e0: 67 22 0a 09 22 66 6d 74 22 0a 09 22 69 6f 22 0a  g".."fmt".."io".
02f0: 09 22 6c 6f 67 22 0a 09 22 6f 73 22 0a 0a 09 22  ."log".."os"..."
0300: 67 6f 6c 61 6e 67 2e 6f 72 67 2f 78 2f 74 65 78  golang.org/x/tex
0310: 74 2f 74 72 61 6e 73 66 6f 72 6d 22 0a 09 22 73  t/transform".."s
0320: 72 63 2e 64 31 30 2e 64 65 76 2f 74 6f 6d 65 2f  rc.d10.dev/tome/
0330: 69 6e 74 65 72 6e 61 6c 2f 74 6f 6d 65 22 0a 09  internal/tome"..
0340: 22 73 72 63 2e 64 31 30 2e 64 65 76 2f 74 6f 6d  "src.d10.dev/tom
0350: 65 2f 74 79 70 73 74 22 0a 29 0a 0a 66 75 6e 63  e/typst".)..func
0360: 20 69 6e 69 74 28 29 20 7b 0a 09 63 6d 64 2e 4f   init() {..cmd.O
0370: 70 65 72 61 74 69 6f 6e 28 22 74 79 70 73 74 22  peration("typst"
0380: 2c 0a 09 09 22 74 79 70 73 74 20 5b 2d 73 75 66  ,..."typst [-suf
0390: 66 69 78 3d 2e 74 79 70 5d 20 5b 44 49 52 45 43  fix=.typ] [DIREC
03a0: 54 4f 52 59 20 2e 2e 2e 5d 22 2c 0a 09 09 22 77  TORY ...]",..."w
03b0: 72 69 74 65 73 20 6e 6f 74 65 73 20 74 6f 20 66  rites notes to f
03c0: 69 6c 65 20 69 6e 20 74 79 70 73 74 20 66 6f 72  ile in typst for
03d0: 6d 61 74 22 2c 0a 09 09 6f 70 54 79 70 73 74 2c  mat",...opTypst,
03e0: 0a 09 29 0a 7d 0a 0a 66 75 6e 63 20 6f 70 54 79  ..).}..func opTy
03f0: 70 73 74 28 29 20 28 65 72 72 20 65 72 72 6f 72  pst() (err error
0400: 29 20 7b 0a 09 64 65 66 65 72 20 66 75 6e 63 28  ) {..defer func(
0410: 29 20 7b 0a 09 09 69 66 20 65 72 72 20 21 3d 20  ) {...if err != 
0420: 6e 69 6c 20 7b 0a 09 09 09 6c 6f 67 2e 50 72 69  nil {....log.Pri
0430: 6e 74 66 28 22 6f 70 54 79 70 73 74 20 66 61 69  ntf("opTypst fai
0440: 6c 65 64 3a 20 25 76 22 2c 20 65 72 72 29 0a 09  led: %v", err)..
0450: 09 7d 0a 09 7d 28 29 0a 0a 09 6d 64 20 3a 3d 20  .}..}()...md := 
0460: 66 6c 61 67 2e 42 6f 6f 6c 28 22 6d 64 22 2c 20  flag.Bool("md", 
0470: 74 72 75 65 2c 20 22 63 6f 6e 76 65 72 74 20 6d  true, "convert m
0480: 61 72 6b 64 6f 77 6e 20 68 65 61 64 65 72 73 20  arkdown headers 
0490: 69 6e 74 6f 20 74 79 70 73 74 20 68 65 61 64 65  into typst heade
04a0: 72 73 22 29 0a 09 6f 75 74 66 69 6c 65 20 3a 3d  rs")..outfile :=
04b0: 20 66 6c 61 67 2e 53 74 72 69 6e 67 28 22 6f 22   flag.String("o"
04c0: 2c 20 22 22 2c 20 22 66 69 6c 65 6e 61 6d 65 20  , "", "filename 
04d0: 77 68 65 72 65 20 74 6f 20 77 72 69 74 65 20 74  where to write t
04e0: 79 70 73 74 20 6d 61 72 6b 75 70 22 29 0a 0a 09  ypst markup")...
04f0: 66 6c 61 67 2e 50 61 72 73 65 28 29 0a 0a 09 69  flag.Parse()...i
0500: 66 20 6c 65 6e 28 53 75 66 66 69 78 29 20 3d 3d  f len(Suffix) ==
0510: 20 30 20 7b 0a 09 09 53 75 66 66 69 78 20 3d 20   0 {...Suffix = 
0520: 5b 5d 73 74 72 69 6e 67 7b 22 2e 74 79 70 22 7d  []string{".typ"}
0530: 0a 09 09 69 66 20 2a 6d 64 20 7b 0a 09 09 09 53  ...if *md {....S
0540: 75 66 66 69 78 20 3d 20 61 70 70 65 6e 64 28 53  uffix = append(S
0550: 75 66 66 69 78 2c 20 22 2e 6d 64 22 29 0a 09 09  uffix, ".md")...
0560: 7d 0a 09 7d 0a 0a 09 61 72 67 20 3a 3d 20 66 6c  }..}...arg := fl
0570: 61 67 2e 41 72 67 73 28 29 0a 09 69 66 20 6c 65  ag.Args()..if le
0580: 6e 28 61 72 67 29 20 3d 3d 20 30 20 7b 0a 09 09  n(arg) == 0 {...
0590: 77 64 2c 20 65 72 72 20 3a 3d 20 6f 73 2e 47 65  wd, err := os.Ge
05a0: 74 77 64 28 29 0a 09 09 69 66 20 65 72 72 20 21  twd()...if err !
05b0: 3d 20 6e 69 6c 20 7b 0a 09 09 09 72 65 74 75 72  = nil {....retur
05c0: 6e 20 65 72 72 0a 09 09 7d 0a 0a 09 09 61 72 67  n err...}....arg
05d0: 20 3d 20 61 70 70 65 6e 64 28 61 72 67 2c 20 77   = append(arg, w
05e0: 64 29 20 2f 2f 20 64 65 66 61 75 6c 74 20 66 69  d) // default fi
05f0: 6e 64 20 63 6f 6e 74 65 6e 74 20 69 6e 20 63 75  nd content in cu
0600: 72 72 65 6e 74 20 64 69 72 65 63 74 6f 72 79 0a  rrent directory.
0610: 09 7d 0a 0a 09 66 69 6c 65 6e 61 6d 65 73 20 3a  .}...filenames :
0620: 3d 20 5b 5d 73 74 72 69 6e 67 7b 7d 0a 09 66 6f  = []string{}..fo
0630: 72 20 69 20 3a 3d 20 72 61 6e 67 65 20 61 72 67  r i := range arg
0640: 20 7b 0a 09 09 6e 61 6d 65 73 2c 20 65 72 72 20   {...names, err 
0650: 3a 3d 20 74 6f 6d 65 2e 46 69 6e 64 53 75 66 66  := tome.FindSuff
0660: 69 78 28 61 72 67 5b 69 5d 2c 20 53 75 66 66 69  ix(arg[i], Suffi
0670: 78 2e 2e 2e 29 0a 09 09 69 66 20 65 72 72 20 21  x...)...if err !
0680: 3d 20 6e 69 6c 20 7b 0a 09 09 09 72 65 74 75 72  = nil {....retur
0690: 6e 20 66 6d 74 2e 45 72 72 6f 72 66 28 22 66 61  n fmt.Errorf("fa
06a0: 69 6c 65 64 20 74 6f 20 66 69 6e 64 20 63 6f 6e  iled to find con
06b0: 74 65 6e 74 20 69 6e 20 64 69 72 65 63 74 6f 72  tent in director
06c0: 79 20 28 25 71 29 3a 20 25 77 22 2c 20 61 72 67  y (%q): %w", arg
06d0: 5b 69 5d 2c 20 65 72 72 29 0a 09 09 7d 0a 09 09  [i], err)...}...
06e0: 73 6f 72 74 41 6c 70 68 61 57 69 74 68 46 69 72  sortAlphaWithFir
06f0: 73 74 28 6e 61 6d 65 73 2c 20 22 52 45 41 44 4d  st(names, "READM
0700: 45 2e 2a 22 29 0a 0a 09 09 2f 2f 20 6f 76 65 72  E.*")....// over
0710: 61 6c 6c 20 6c 69 73 74 20 70 72 65 73 65 72 76  all list preserv
0720: 65 73 20 64 69 72 65 63 74 6f 72 79 20 6f 72 64  es directory ord
0730: 65 72 20 6f 66 20 61 72 67 73 0a 09 09 66 69 6c  er of args...fil
0740: 65 6e 61 6d 65 73 20 3d 20 61 70 70 65 6e 64 28  enames = append(
0750: 66 69 6c 65 6e 61 6d 65 73 2c 20 6e 61 6d 65 73  filenames, names
0760: 2e 2e 2e 29 0a 09 7d 0a 0a 09 6f 75 74 20 3a 3d  ...)..}...out :=
0770: 20 6f 73 2e 53 74 64 6f 75 74 0a 09 6c 6f 67 2e   os.Stdout..log.
0780: 50 72 69 6e 74 66 28 22 6f 75 74 66 69 6c 65 20  Printf("outfile 
0790: 28 25 71 29 22 2c 20 2a 6f 75 74 66 69 6c 65 29  (%q)", *outfile)
07a0: 0a 09 69 66 20 2a 6f 75 74 66 69 6c 65 20 21 3d  ..if *outfile !=
07b0: 20 22 22 20 7b 0a 09 09 6f 75 74 2c 20 65 72 72   "" {...out, err
07c0: 20 3d 20 6f 73 2e 4f 70 65 6e 46 69 6c 65 28 2a   = os.OpenFile(*
07d0: 6f 75 74 66 69 6c 65 2c 20 6f 73 2e 4f 5f 52 44  outfile, os.O_RD
07e0: 57 52 7c 6f 73 2e 4f 5f 43 52 45 41 54 45 7c 6f  WR|os.O_CREATE|o
07f0: 73 2e 4f 5f 54 52 55 4e 43 2c 20 30 36 30 30 29  s.O_TRUNC, 0600)
0800: 0a 09 09 69 66 20 65 72 72 20 21 3d 20 6e 69 6c  ...if err != nil
0810: 20 7b 0a 09 09 09 72 65 74 75 72 6e 20 66 6d 74   {....return fmt
0820: 2e 45 72 72 6f 72 66 28 22 63 61 6e 6e 6f 74 20  .Errorf("cannot 
0830: 6f 70 65 6e 20 6f 75 74 70 75 74 20 66 69 6c 65  open output file
0840: 20 28 25 71 29 3a 20 25 77 22 2c 20 2a 6f 75 74   (%q): %w", *out
0850: 66 69 6c 65 2c 20 65 72 72 29 0a 09 09 7d 0a 09  file, err)...}..
0860: 09 64 65 66 65 72 20 66 75 6e 63 28 29 20 7b 0a  .defer func() {.
0870: 09 09 09 65 72 72 20 3d 20 65 72 72 6f 72 73 2e  ...err = errors.
0880: 4a 6f 69 6e 28 65 72 72 2c 20 6f 75 74 2e 43 6c  Join(err, out.Cl
0890: 6f 73 65 28 29 29 0a 09 09 7d 28 29 0a 09 7d 0a  ose())...}()..}.
08a0: 0a 09 2f 2f 20 6f 6e 65 2d 74 69 6d 65 20 64 65  ..// one-time de
08b0: 66 69 6e 69 74 69 6f 6e 73 20 61 74 20 74 6f 70  finitions at top
08c0: 20 6f 66 20 74 79 70 20 66 69 6c 65 0a 09 5f 2c   of typ file.._,
08d0: 20 65 72 72 20 3d 20 66 6d 74 2e 46 70 72 69 6e   err = fmt.Fprin
08e0: 74 28 6f 75 74 2c 20 68 65 61 64 65 72 29 0a 09  t(out, header)..
08f0: 69 66 20 65 72 72 20 21 3d 20 6e 69 6c 20 7b 0a  if err != nil {.
0900: 09 09 72 65 74 75 72 6e 20 66 6d 74 2e 45 72 72  ..return fmt.Err
0910: 6f 72 66 28 22 66 61 69 6c 65 64 20 74 6f 20 77  orf("failed to w
0920: 72 69 74 65 20 74 79 70 73 74 20 68 65 61 64 65  rite typst heade
0930: 72 3a 20 25 77 22 2c 20 65 72 72 29 0a 09 7d 0a  r: %w", err)..}.
0940: 0a 09 66 6f 72 20 5f 2c 20 6e 61 6d 65 20 3a 3d  ..for _, name :=
0950: 20 72 61 6e 67 65 20 66 69 6c 65 6e 61 6d 65 73   range filenames
0960: 20 7b 0a 09 09 66 2c 20 65 72 72 20 3a 3d 20 6f   {...f, err := o
0970: 73 2e 4f 70 65 6e 28 6e 61 6d 65 29 0a 09 09 69  s.Open(name)...i
0980: 66 20 65 72 72 20 21 3d 20 6e 69 6c 20 7b 0a 09  f err != nil {..
0990: 09 09 72 65 74 75 72 6e 20 65 72 72 0a 09 09 7d  ..return err...}
09a0: 0a 09 09 6c 6f 67 2e 50 72 69 6e 74 66 28 22 74  ...log.Printf("t
09b0: 72 61 6e 73 66 6f 72 6d 69 6e 67 20 66 69 6c 65  ransforming file
09c0: 20 25 71 22 2c 20 6e 61 6d 65 29 0a 0a 09 09 76   %q", name)....v
09d0: 61 72 20 78 66 6f 72 6d 20 5b 5d 74 72 61 6e 73  ar xform []trans
09e0: 66 6f 72 6d 2e 54 72 61 6e 73 66 6f 72 6d 65 72  form.Transformer
09f0: 0a 09 09 69 66 20 2a 6d 64 20 7b 0a 09 09 09 78  ...if *md {....x
0a00: 66 6f 72 6d 20 3d 20 61 70 70 65 6e 64 28 78 66  form = append(xf
0a10: 6f 72 6d 2c 20 74 79 70 73 74 2e 4e 65 77 4d 64  orm, typst.NewMd
0a20: 28 6e 61 6d 65 29 2e 2e 2e 29 0a 09 09 7d 0a 09  (name)...)...}..
0a30: 09 2f 2f 20 6c 61 73 74 0a 09 09 78 66 6f 72 6d  .// last...xform
0a40: 20 3d 20 61 70 70 65 6e 64 28 78 66 6f 72 6d 2c   = append(xform,
0a50: 20 74 79 70 73 74 2e 4e 65 77 28 6e 61 6d 65 29   typst.New(name)
0a60: 29 0a 0a 09 09 2f 2f 20 61 76 6f 69 64 20 74 72  )....// avoid tr
0a70: 61 6e 73 66 6f 72 6d 2e 43 68 61 69 6e 20 62 65  ansform.Chain be
0a80: 63 61 75 73 65 20 69 74 20 68 61 73 20 61 20 66  cause it has a f
0a90: 69 78 65 64 20 64 73 74 20 62 75 66 66 65 72 20  ixed dst buffer 
0aa0: 73 69 7a 65 2c 20 73 6f 20 77 65 27 64 20 66 61  size, so we'd fa
0ab0: 69 6c 20 77 69 74 68 20 45 72 72 53 68 6f 72 74  il with ErrShort
0ac0: 44 73 74 0a 09 09 2f 2f 20 61 63 74 75 61 6c 6c  Dst...// actuall
0ad0: 79 20 70 72 6f 62 6c 65 6d 20 77 69 74 68 20 63  y problem with c
0ae0: 68 61 69 6e 20 77 61 73 20 70 72 6f 62 61 62 6c  hain was probabl
0af0: 79 20 6d 69 73 75 6e 64 65 72 73 74 61 6e 64 69  y misunderstandi
0b00: 6e 67 20 6f 66 20 68 6f 77 20 45 72 72 53 68 6f  ng of how ErrSho
0b10: 72 74 44 73 74 20 77 6f 72 6b 73 2c 20 69 74 20  rtDst works, it 
0b20: 70 72 6f 62 61 62 6c 79 20 77 6f 75 6c 64 20 77  probably would w
0b30: 6f 72 6b 20 61 73 20 69 6e 74 65 6e 64 65 64 0a  ork as intended.
0b40: 0a 09 09 2f 2f 20 76 61 72 20 70 69 70 65 6c 69  ...// var pipeli
0b50: 6e 65 20 69 6f 2e 57 72 69 74 65 72 20 3d 20 6f  ne io.Writer = o
0b60: 75 74 0a 09 09 2f 2f 20 66 6f 72 20 5f 2c 20 78  ut...// for _, x
0b70: 20 3a 3d 20 72 61 6e 67 65 20 78 66 6f 72 6d 20   := range xform 
0b80: 7b 0a 09 09 2f 2f 20 09 74 77 20 3a 3d 20 74 72  {...// .tw := tr
0b90: 61 6e 73 66 6f 72 6d 2e 4e 65 77 57 72 69 74 65  ansform.NewWrite
0ba0: 72 28 70 69 70 65 6c 69 6e 65 2c 20 78 29 0a 09  r(pipeline, x)..
0bb0: 09 2f 2f 20 09 64 65 66 65 72 20 74 77 2e 43 6c  .// .defer tw.Cl
0bc0: 6f 73 65 28 29 0a 09 09 2f 2f 20 09 70 69 70 65  ose()...// .pipe
0bd0: 6c 69 6e 65 20 3d 20 74 77 0a 09 09 2f 2f 20 7d  line = tw...// }
0be0: 0a 0a 09 09 70 69 70 65 6c 69 6e 65 20 3a 3d 20  ....pipeline := 
0bf0: 74 72 61 6e 73 66 6f 72 6d 2e 4e 65 77 57 72 69  transform.NewWri
0c00: 74 65 72 28 6f 75 74 2c 20 74 72 61 6e 73 66 6f  ter(out, transfo
0c10: 72 6d 2e 43 68 61 69 6e 28 78 66 6f 72 6d 2e 2e  rm.Chain(xform..
0c20: 2e 29 29 0a 09 09 64 65 66 65 72 20 70 69 70 65  .))...defer pipe
0c30: 6c 69 6e 65 2e 43 6c 6f 73 65 28 29 0a 0a 09 09  line.Close()....
0c40: 5f 2c 20 65 72 72 20 3d 20 69 6f 2e 43 6f 70 79  _, err = io.Copy
0c50: 28 70 69 70 65 6c 69 6e 65 2c 20 66 29 0a 09 09  (pipeline, f)...
0c60: 69 66 20 65 72 72 20 21 3d 20 6e 69 6c 20 7b 0a  if err != nil {.
0c70: 09 09 09 72 65 74 75 72 6e 20 65 72 72 0a 09 09  ...return err...
0c80: 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 20 6e 69  }..}...return ni
0c90: 6c 0a 7d 0a 0a 63 6f 6e 73 74 20 68 65 61 64 65  l.}..const heade
0ca0: 72 20 3d 20 60 0a 2f 2f 20 73 74 79 6c 65 0a 23  r = `.// style.#
0cb0: 73 68 6f 77 20 6c 69 6e 6b 3a 20 75 6e 64 65 72  show link: under
0cc0: 6c 69 6e 65 0a 23 73 68 6f 77 20 6c 69 6e 6b 3a  line.#show link:
0cd0: 20 73 65 74 20 74 65 78 74 28 62 6c 75 65 29 0a   set text(blue).
0ce0: 0a 2f 2f 20 70 72 65 76 65 6e 74 20 62 72 6f 6b  .// prevent brok
0cf0: 65 6e 20 6c 69 6e 6b 73 20 66 72 6f 6d 20 62 72  en links from br
0d00: 65 61 6b 69 6e 67 20 63 6f 6d 70 69 6c 65 0a 23  eaking compile.#
0d10: 73 68 6f 77 20 6c 69 6e 6b 3a 20 69 74 20 3d 3e  show link: it =>
0d20: 20 7b 0a 20 20 69 66 20 74 79 70 65 28 69 74 2e   {.  if type(it.
0d30: 64 65 73 74 29 20 21 3d 20 6c 61 62 65 6c 20 7b  dest) != label {
0d40: 0a 20 20 20 20 72 65 74 75 72 6e 20 69 74 0a 20  .    return it. 
0d50: 20 7d 0a 20 20 69 66 20 71 75 65 72 79 28 69 74   }.  if query(it
0d60: 2e 64 65 73 74 29 2e 6c 65 6e 28 29 20 3e 20 30  .dest).len() > 0
0d70: 20 7b 0a 20 20 20 20 69 74 0a 20 20 7d 20 65 6c   {.    it.  } el
0d80: 73 65 20 7b 0a 20 20 20 20 74 65 78 74 28 66 69  se {.    text(fi
0d90: 6c 6c 3a 20 72 65 64 29 5b 23 69 74 2e 62 6f 64  ll: red)[#it.bod
0da0: 79 5d 0a 20 20 7d 0a 7d 0a 0a 60 0a              y].  }.}..`.