tuberry / light-dict

Lightweight extension for on-the-fly manipulation to primary selections, especially optimized for Dictionary lookups.
GNU General Public License v3.0
34 stars 1 forks source link

Pango markup fails to render if the text is of bigger size #22

Closed nbCloud91 closed 1 year ago

nbCloud91 commented 1 year ago

I do not know the exact threshold of when this happens but pango markup does not get rendered when the text is too big. Below are two examples:

  1. Definition of "background"
    
    Found 1 items, similar to background.

Background

Background \Back"ground`\, n. [Back, a. + ground.]

  1. Ground in the rear or behind, or in the distance, as opposed to the foreground, or the ground in front.

  2. (Paint.) The space which is behind and subordinate to a portrait or group of figures.

    Note: The distance in a picture is usually divided into foreground, middle distance, and background. --Fairholt.

  3. Anything behind, serving as a foil; as, the statue had a background of red hangings.

  4. A place in obscurity or retirement, or out of sight.

        I fancy there was a background of grinding and
        waiting before Miss Torry could produce this highly
        finished . . . performance.           --Mrs.
                                              Alexander.
    
        A husband somewhere in the background. --Thackeray.
Which is rendered as:
![Screenshot from 2023-02-09 18-47-54](https://user-images.githubusercontent.com/73609114/217825153-b03cc12a-8ba3-4f4d-87f7-f71b4aa0dcd2.png)
2. Definition of "color"
```pango
Found 1 items, similar to color.

<span size="x-large"><b>Color</b></span>

Color \Col"or\, n. [Written also {colour}.] [OF. color, colur,
   colour, F. couleur, L. color; prob. akin to celare to conceal
   (the color taken as that which covers). See {Helmet}.]
   1. A property depending on the relations of light to the eye,
      by which individual and specific differences in the hues
      and tints of objects are apprehended in vision; as, gay
      colors; sad colors, etc.

   Note: The sensation of color depends upon a peculiar function
         of the retina or optic nerve, in consequence of which
         rays of light produce different effects according to
         the length of their waves or undulations, waves of a
         certain length producing the sensation of red, shorter
         waves green, and those still shorter blue, etc. White,
         or ordinary, light consists of waves of various lengths
         so blended as to produce no effect of color, and the
         color of objects depends upon their power to absorb or
         reflect a greater or less proportion of the rays which
         fall upon them.

   2. Any hue distinguished from white or black.

   3. The hue or color characteristic of good health and
      spirits; ruddy complexion.

            Give color to my pale cheek.          --Shak.

   4. That which is used to give color; a paint; a pigment; as,
      oil colors or water colors.

   5. That which covers or hides the real character of anything;
      semblance; excuse; disguise; appearance.

            They had let down the boat into the sea, under color
            as though they would have cast anchors out of the
            foreship.                             --Acts xxvii.
                                                  30.

            That he should die is worthy policy; But yet we want
            a color for his death.                --Shak.

   6. Shade or variety of character; kind; species.

            Boys and women are for the most part cattle of this
            color.                                --Shak.

   7. A distinguishing badge, as a flag or similar symbol
      (usually in the plural); as, the colors or color of a ship
      or regiment; the colors of a race horse (that is, of the
      cap and jacket worn by the jockey).

            In the United States each regiment of infantry and
            artillery has two colors, one national and one
            regimental.                           --Farrow.

   8. (Law) An apparent right; as where the defendant in
      trespass gave to the plaintiff an appearance of title, by
      stating his title specially, thus removing the cause from
      the jury to the court. --Blackstone.

   Note: Color is express when it is averred in the pleading,
         and implied when it is implied in the pleading.

   {Body color}. See under {Body}.

   {Color blindness}, total or partial inability to distinguish
      or recognize colors. See {Daltonism}.

   {Complementary color}, one of two colors so related to each
      other that when blended together they produce white light;
      -- so called because each color makes up to the other what
      it lacks to make it white. Artificial or pigment colors,
      when mixed, produce effects differing from those of the
      primary colors, in consequence of partial absorption.

   {Of color} (as persons, races, etc.), not of the white race;
      -- commonly meaning, esp. in the United States, of negro
      blood, pure or mixed.

   {Primary colors}, those developed from the solar beam by the
      prism, viz., red, orange, yellow, green, blue, indigo, and
      violet, which are reduced by some authors to three, --
      red, green, and violet-blue. These three are sometimes
      called {fundamental colors}.

   {Subjective} or {Accidental color}, a false or spurious color
      seen in some instances, owing to the persistence of the
      luminous impression upon the retina, and a gradual change
      of its character, as where a wheel perfectly white, and
      with a circumference regularly subdivided, is made to
      revolve rapidly over a dark object, the teeth of the wheel
      appear to the eye of different shades of color varying
      with the rapidity of rotation. See {Accidental colors},
      under {Accidental}.

Color \Col"or\, v. t. [imp. & p. p. {Colored}; p. pr. & vb. n.
   {Coloring}.] [F. colorer.]
   1. To change or alter the hue or tint of, by dyeing,
      staining, painting, etc.; to dye; to tinge; to paint; to
      stain.

            The rays, to speak properly, are not colored; in
            them there is nothing else than a certain power and
            disposition to stir up a sensation of this or that
            color.                                --Sir I.
                                                  Newton.

   2. To change or alter, as if by dyeing or painting; to give a
      false appearance to; usually, to give a specious
      appearance to; to cause to appear attractive; to make
      plausible; to palliate or excuse; as, the facts were
      colored by his prejudices.

            He colors the falsehood of [AE]neas by an express
            command from Jupiter to forsake the queen. --Dryden.

   3. To hide. [Obs.]

            That by his fellowship he color might Both his
            estate and love from skill of any wight. --Spenser.

Color \Col"or\, v. i.
   To acquire color; to turn red, especially in the face; to
   blush.

which is rendered as: Screenshot from 2023-02-09 18-54-28

tuberry commented 1 year ago

The reserved characters (<>&...) in SGML-like language (Pango, HTML...) should be escaped to be parsed correctly, so the culprit is & in line 100:

Color \Col"or\, v. t. [imp. & p. p. {Colored}; p. pr. & vb. n.

const { Pango, GLib } = imports.gi;
let s = 'Color \\Col"or\\, v. t. [imp. & p. p. {Colored}; p. pr. & vb. n.';
Pango.parse_markup(s, -1, ''); // error
Pango.parse_markup(GLib.markup_escape_text(s, -1), -1, ''); // ok

See also https://docs.rs/html2pango/latest/html2pango/#escaping and https://gjs-docs.gnome.org/glib20~2.0/glib.markup_escape_text.

nbCloud91 commented 1 year ago

Thank you!