taontech / githublog

一个基于github issues的博客系统,实时呈现,零依赖,零代码部署,不用打包不用上线。
4 stars 1 forks source link

图片自动适应大小完成 #15

Open taontech opened 2 years ago

taontech commented 2 years ago

~直接用的common mark.js 但是github上就可以,一定是有什么设置没弄好~

简单改了下 commonmark库,暂时加了个100%宽度,看起来可以了。

CSS太坑

找到 下面的方法,给style加上 width=100%;

    function image$1(node, entering) {
        if (entering) {
            if (this.disableTags === 0) {
                if (this.options.safe && potentiallyUnsafe(node.destination)) {
                    this.lit('<img src="" width=100%; alt=" ');
                } else {
                    this.lit('<img src="' + this.esc(node.destination) + '" width=100%; alt="');
                }
            }
            this.disableTags += 1;
        } else {
            this.disableTags -= 1;
            if (this.disableTags === 0) {
                if (node.title) {
                    this.lit('" title="' + this.esc(node.title));
                }
                this.lit('" />');
            }
        }
    }

但是, 这样做的会导致小图片也会被拉伸到100%。 所以改成这样子:max-width=100%,遗憾的是大图就不起作用了。 需要改成 style="max-width: 100%;",经常忘记的选项,但是width=100%写在这里就好使

    function image$1(node, entering) {
        if (entering) {
            if (this.disableTags === 0) {
                if (this.options.safe && potentiallyUnsafe(node.destination)) {
                    this.lit('<img src="" style="max-width: 100%;" alt=" ');
                } else {
                    this.lit('<img src="' + this.esc(node.destination) + '" style="max-width: 100%;" alt="');
                }
            }
            this.disableTags += 1;
        } else {
            this.disableTags -= 1;
            if (this.disableTags === 0) {
                if (node.title) {
                    this.lit('" title="' + this.esc(node.title));
                }
                this.lit('" />');
            }
        }
    }

效果就变成了下面的样子 小图:

小图

大图:

image

taontech commented 2 years ago

用的同一个库,但是GitHub可以

taontech commented 2 years ago

波浪线没起作用