简体   繁体   中英

how to fit the html output from difflib.HtmlDiff in one window without the scroll bar

How to fit the html output from difflib.HtmlDiff in one window without the scroll bar.

I am attaching my html output image in here: output html

For the horizontal scrollbar, you can reduce the width of the table using the optional wrapcolumn argument when creating the difflib.HtmlDiff object.

html_table = difflib.HtmlDiff(wrapcolumn=80).make_table(
    expected,
    actual,
)

If you meant the vertical scrollbar, you can reduce the height by using context=True in the make_table or make_file function call. You can tweak the numlines argument too if you want.

difflib.HtmlDiff doesn't provide much else for customization, and I've found it very difficult to customize the look using CSS. The HTML it generates is very archaic and inflexible.

https://docs.python.org/3/library/difflib.html#difflib.HtmlDiff

There are some suggestions for alternatives to difflib.HtmlDiff in this question , though.

There are a few things you can do.

  • If the output is in a container like a table or a div you can set the width to 100%
  • If the output is in a table you can set the cell width's {.outputDiv table .cell1 width:50px} ....
  • You can use css to remove the scrollbar .outputDiv {overflow-x: hidden;}. This will hide all content that won't fit in your outputDiv though so be sure that it is sized correctly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM