Skip to content

Commit

Permalink
improve toc
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ging committed Feb 23, 2024
1 parent fae2c17 commit d8d9e0e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ This repository contains the official implementation of our [paper](https://arxi
**"Open-ended VQA benchmarking of Vision-Language models by exploiting Classification datasets and their semantic hierarchy"**
accepted to ICLR 2024.

<!--TOC-->

- [oVQA: Open-ended Visual Question Answering](#ovqa-open-ended-visual-question-answering)
- [News](#news)
- [Setup](#setup)
- [Python environment](#python-environment)
- [Notes](#notes)
- [Setup the paths](#setup-the-paths)
- [Setup datasets](#setup-datasets)
- [Setup model outputs](#setup-model-outputs)
- [Setup model checkpoints](#setup-model-checkpoints)
- [Setup metrics](#setup-metrics)
- [Running](#running)
- [Dev commands](#dev-commands)
- [Licenses](#licenses)
- [Acknowledgements](#acknowledgements)
- [Citation](#citation)

<!--TOC-->
<!--TOC-->

- [News](#news)
- [Setup](#setup)
- [Python environment](#python-environment)
- [Notes](#notes)
- [Setup the paths](#setup-the-paths)
- [Setup datasets](#setup-datasets)
- [Setup model outputs](#setup-model-outputs)
- [Setup model checkpoints](#setup-model-checkpoints)
- [Setup metrics](#setup-metrics)
- [Running](#running)
- [Dev commands](#dev-commands)
- [Licenses](#licenses)
- [Acknowledgements](#acknowledgements)
- [Citation](#citation)

<!--TOC-->


## News
Expand Down
40 changes: 40 additions & 0 deletions update_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Same logic as md-toc package except skipping h1 and forcing unix newlines.
"""

from pathlib import Path

import md_toc


def main():
file = Path("README.md")
toc = md_toc.build_toc(file.as_posix(), keep_header_levels=3)
content = file.read_text().replace("\r\n", "\n")
marker = "<!--TOC-->"
marker_splits = content.split(marker)
if len(marker_splits) == 2:
before, after = marker_splits
elif len(marker_splits) == 3:
before, _old_toc, after = marker_splits
else:
raise ValueError(
f"Marker {marker} found {len(marker_splits) - 1} times in {file}, expected 1 or 2."
)
toc = toc.replace("\r\n", "\n")
new_toc = []
for line in toc.splitlines():
if line.startswith("- "):
continue
elif line.startswith(" "):
line = line[2:]
new_toc.append(line)
toc = "\n".join(new_toc)
print(toc)
file.write_text(
before + marker + "\n\n" + toc + "\n\n" + marker + after, encoding="utf-8", newline="\n"
)


if __name__ == "__main__":
main()

0 comments on commit d8d9e0e

Please sign in to comment.