Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

资源定位的时候对 <a> 及 <iframe> 是否支持 #843

Open
zhangyihua opened this issue Jul 5, 2016 · 4 comments
Open

资源定位的时候对 <a> 及 <iframe> 是否支持 #843

zhangyihua opened this issue Jul 5, 2016 · 4 comments

Comments

@zhangyihua
Copy link

我的配置如下:

fis .match('**{.html}', {
      domain: 'http://demo.example.com/myproject/path'
 })

但是我 html 文件里的 <a> 标签的 href<iframe>src 所引用的 URL 没有被替换。

FIS3 支持对html中的script、link、style、video、audio、embed等标签的src或href属性进行分析,一旦这些标签的资源定位属性可以命中已存在文件,则把命中文件的url路径替换到属性中,同时可保留原来url中的query查询信息。

这是文档的说明,我不知道 是否包含有这两种情况?如果没有,目前是否有好的解决方案?

THX

@sealice
Copy link

sealice commented Aug 3, 2016

[fis3的这个项目是用定义一个变量来替换的,具体的你可以看下fis3/doc
我的解决方法:打开fis3源码目录下的 lib/compile.js 文件找到如下代码对应红框的位置修改(注意看行号)就行了
image
image

@zhangyihua
Copy link
Author

谢谢 @sealice

@nimoc
Copy link

nimoc commented Nov 1, 2016

今天也遇到这个问题,最终按照@sealice 贴出的方法,在 parser阶段重复做了一次 extHtml 操作

https://coding.net/u/nimojs/p/fis-a-href/git/blob/master/fis-conf.js

我现在用 fis 编译 markdown 为 html,因为这个markdown是 第三方组件的文档,最终我要发布到 github page ,所以我需要 a链接能支持资源定位。

目前我很担心这种重复 extHtml 操作留下坑,毕竟我自己复制的 extHtml 函数不会随着 fis 的版本更新而更新。

@2betop @xiangshouding 是否考虑在文件属性中增加一项 指定当前文件进行 <a href 的资源定位?

@wcxaa
Copy link

wcxaa commented Jun 22, 2017

我是这样解决的:
在fis-config中加入:

// 扩展a标签的资源定位能力
fis.match('**.{html,tpl,php}', {
    postprocessor: function(content, file, settings) {
        var re = /<a\s+[\s\S]*?["'\s\w\/\-](?:>|$)/gi;
        return content = content.replace(re, function(m, p1) {
            return m.replace(/\s+href\s*=\s*(?:'([^']+)'|"([^"]+)"|([^\s\/>]+))/i, function(m, p1, p2, p3) {
                var matched = p1 || p2 || p3;
                return (matched && m.replace(matched, function(to) {
                    if (fis.util.exists(to)) {
                        return to;
                    }
                    var f = fis.uri(to, path.dirname(file.realpath)).file;
                    return (f && f.url) || to;
                })) || m;
            });
        });
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants