0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PlantUML の SourceStringReader.generateImage() は deprecated だってさ

Last updated at Posted at 2025-12-27

概要

GitBucket用のプラグイン GitBucket Markdown Enhanced Pluginを開発しています。

GitBucket Markdown Enhanced Plugin は、GitBucket 標準のマークダウンレンダリングエンジンを置き換えるプラグインです。

目標は、Visual Studio CodeMarkdown Preview Enhanced 向けの markdown ファイルを軽易に Web で共有できる環境です。

今回は、PlantUML でガントチャートが描画できないことに気づいたので PlantUML のバージョンを変更してみました。

その際、既存のコードのコンパイル時に警告が表示されたため、調査した結果について記事にします。

前回の記事

出力された警告

method generateImage in class SourceStringReader is deprecated[warn] \path\to\gitbucket-markdown-enhanced\src\main\scala\io\github\yasumichi\gme\MarkdownEnhancedNodeRenderer.scala:161:12: method generateImage in class SourceStringReader is deprecated
[warn]     reader.generateImage(os, new FileFormatOption(FileFormat.SVG))
[warn]            ^
[warn] one warning found

SourceStringReader クラスの generateImage() メソッドは deprecated だそうです。

対処

代わりに outputImage() メソッドを使えば良いようです。

  /**
    * Renders SVG from the given PlantUML or dot text.
    *
    * @param html HtmlWriter to write the output.
    * @param text The PlantUML or dot text to render.
    */
  private def renderSVG(html: HtmlWriter, text: String): Unit = {
    val reader = new SourceStringReader(text)
    val os = new ByteArrayOutputStream()
    reader.outputImage(os, new FileFormatOption(FileFormat.SVG))
    os.close()

    var svg = new String(os.toByteArray(), Charset.forName("UTF-8"))
    var re = "^<\\?xml [^<>]+?\\>".r
    svg = re.replaceFirstIn(svg, "")

    html.tag("div")
    html.append(svg)
    html.tag("/div")
  }

余談

あと、テーブルの右寄せが gitbucket.css に打ち消されるんだけど…

次のコードが、gitbucket側でのテーブル出力の例です。

   <td>cell 21</td>
   <td style="text-align: left">cell 22</td>
   <td style="text-align: center">cell 22</td>
   <td style="text-align: right">cell 22</td>

これに対し、GitBucket Markdown Enhanced Plugin側のテーブル出力の例です。

<td>cell 21</td><td align="left">cell 22</td><td align="center">cell 22</td><td align="right">cell 22</td>

align 属性がまったく効かないので調査したところ、gitbucket のスタイルシートに text-align 属性が指定されていました。

gitbucket.css
div.markdown-body table th,
div.markdown-body table td {
  padding: 8px;
  line-height: 20px;
  text-align: left;
  vertical-align: top;
  border-top: 1px solid #dddddd;
}

これに負けちゃうので JavaScript で暫定対処しています。text-align の指定いるかな…。ということで以下のプルリクエストを発行しました。

I think it is unnecessary to set text-align in the cells of a table created with markdown. #3899

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?