You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何指定DITA imagemap转HTML时关联img与map的固定ID?

为DITA Imagemap生成的HTML组件指定固定关联ID

可以指定固定ID来避免DITA-OT每次生成随机ID导致的版本控制冗余变更,具体操作如下:

1. 给DITA中的imagemap元素添加固定ID

在你的DITA主题文件里,直接为<imagemap>标签添加@id属性,示例:

<imagemap id="dashboard_nav_map">
  <image href="dashboard.png" />
  <area shape="circle" coords="50,50,30" href="overview.dita" />
  <area shape="rect" coords="100,20,200,80" href="settings.dita" />
</imagemap>

2. 配置DITA-OT强制使用自定义ID

默认DITA-OT会自动生成随机ID,你需要通过构建参数禁用这个行为,强制使用你指定的ID:

  • 在构建命令中添加参数:-Dwebhelp.imagemap.id.use-fixed=true
  • 或者在项目的DITA-OT构建配置文件(比如build.xml)中设置该参数为true

3. 验证生成的HTML代码

构建完成后,检查输出的HTML,会看到:

<img src="dashboard.png" usemap="#dashboard_nav_map" alt="Dashboard Navigation" />
<map id="dashboard_nav_map">
  <area shape="circle" coords="50,50,30" href="overview.html" />
  <area shape="rect" coords="100,20,200,80" href="settings.html" />
</map>

此时<img>的usemap和<map>的id都会使用你指定的固定值,不会再随构建生成新ID。

注意:如果项目中有多个imagemap,要保证每个的@id唯一,避免页面内ID冲突。

内容的提问来源于stack exchange,提问作者ianmayo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 03:05:05