Skip to content

Commit

Permalink
Merge pull request #1 from buildingSMART/master
Browse files Browse the repository at this point in the history
Fetch from bSI master
  • Loading branch information
evandroAlfieri authored Jul 3, 2023
2 parents 2b3619e + 6771cb5 commit ffbe9a2
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 78 deletions.
2 changes: 1 addition & 1 deletion code/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y curl
# remove policy to disable PDF conversion
RUN rm /etc/ImageMagick-6/policy.xml
RUN curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python3
RUN python3 -m pip install flask Beautifulsoup4 lxml Markdown gunicorn pysolr pydot tabulate hilbertcurve==1.0.5 markdown-it-py==1.1.0 deepdiff redis "pyparsing<3" networkx xmlschema
RUN python3 -m pip install flask "Beautifulsoup4<4.12" lxml Markdown gunicorn pysolr pydot tabulate hilbertcurve==1.0.5 markdown-it-py==1.1.0 deepdiff redis "pyparsing<3" networkx xmlschema

RUN curl --location --silent --show-error --retry 5 'https://archive.apache.org/dist/lucene/solr/8.6.3/solr-8.6.3.tgz' -o - | tar zxf -
RUN chmod +x /solr-8.6.3/bin/*
Expand Down
79 changes: 61 additions & 18 deletions code/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def property(prop):
)


def process_markdown(resource, mdc):
def process_markdown(resource, mdc, process_quotes=True, number_headings=False, chapter=None):
html = markdown.markdown(process_graphviz(resource, mdc), extensions=["tables", "fenced_code"])

soup = BeautifulSoup(html)
Expand All @@ -890,6 +890,33 @@ def process_markdown(resource, mdc):
else:
img["src"] = img["src"][9:]

if number_headings:
assert chapter

headings = soup.find_all(re.compile("h\d"))

stack = list(chapter)
orig_length = len(stack) - 1

for h in headings:
level = int(h.name[1:]) + orig_length
if level == len(stack):
stack[-1] += 1
elif len(stack) < level:
stack += [1] * (level - len(stack))
else:
stack = stack[0:level]
stack[-1] += 1

span1 = soup.new_tag('div')
span1['class'] = 'number'
span1.string = ".".join(map(str, stack))

span2 = soup.new_tag('div')
span2.string = h.text

h.contents = [span1, span2]

for svg in soup.findAll("svg"):
# Graphviz diagrams use pt, a hackish way to isolate them
if "pt" in svg.attrs["width"]:
Expand All @@ -916,15 +943,16 @@ def process_markdown(resource, mdc):
has_aside = True
p.name = "aside"

if keyword.startswith("IFC"):
# This is typically something like "IFC4 CHANGE" denoting a historic change reason
keyword, keyword2, contents = p.text.split(" ", 2)
p.contents = BeautifulSoup(str(p).replace(keyword + " " + keyword2, "")).html.body.aside.contents
keyword = keyword.strip()
keyword2 = keyword2.strip()
keyword = "-".join((keyword, keyword2))
else:
p.contents = BeautifulSoup(str(p).replace(keyword, "")).html.body.aside.contents
if process_quotes:
if keyword.startswith("IFC"):
# This is typically something like "IFC4 CHANGE" denoting a historic change reason
keyword, keyword2, contents = p.text.split(" ", 2)
p.contents = BeautifulSoup(str(p).replace(keyword + " " + keyword2, "")).html.body.aside.contents
keyword = keyword.strip()
keyword2 = keyword2.strip()
keyword = "-".join((keyword, keyword2))
else:
p.contents = BeautifulSoup(str(p).replace(keyword, "")).html.body.aside.contents

css_class = keyword.lower()
if "addendum" in css_class or "change" in css_class:
Expand All @@ -938,13 +966,14 @@ def process_markdown(resource, mdc):
mark.string = keyword

if "deprecation" in css_class:
anchor = soup.new_tag("a", href="/IFC/RELEASE/IFC4x3/HTML/content/terms_and_definitions.htm#3.1.30-deprecation")
anchor = soup.new_tag("a", href="/IFC/RELEASE/IFC4x3/HTML/content/terms_and_definitions.htm#deprecation")
icon = soup.new_tag("i")
icon["data-feather"] = "link"
anchor.append(icon)
mark.append(anchor)

p.insert(0, mark)
if process_quotes:
p.insert(0, mark)
blockquote.insert_before(p)

if has_aside:
Expand Down Expand Up @@ -1878,7 +1907,14 @@ def content(s):
template = Environment(loader=BaseLoader).from_string(content)
content = template.render(is_iso=X.is_iso)

html = process_markdown("", render_template_string(content, base=base, is_iso=X.is_iso))
process_quotes = s != "terms_and_definitions"

if s == "terms_and_definitions":
kwargs = {'number_headings': True, 'chapter': (int(number), 1)}
else:
kwargs = {}

html = process_markdown("", render_template_string(content, base=base, is_iso=X.is_iso), process_quotes=process_quotes, **kwargs)

return render_template(
"static.html",
Expand Down Expand Up @@ -2297,20 +2333,27 @@ def after(response):
for element in soup.findAll(["h2", "h3", "h4", "h5", "h6", "figure"]):
id_element = element

if element.name == "figure":
element = element.findChild("figcaption", recursive=False)
value = element.text.strip()
divs = element.find_all("div")
if element.name[0] == "h" and len(divs) == 2 and 'number' in divs[0]['class']:
# terms and defs
anchor_tag = divs[1].text.strip()
else:
value = element.text.strip()
if element.name == "figure":
element = element.findChild("figcaption", recursive=False)
value = element.text.strip()
else:
value = element.text.strip()

anchor_tag = re.sub("[^0-9a-zA-Z.]+", "-", value)
anchor_tag = re.sub("[^0-9a-zA-Z.]+", "-", value)

anchor_id = soup.new_tag("a")
anchor_id["id"] = anchor_tag
anchor_id["class"] = "anchor"
id_element.insert(0, anchor_id)

anchor = soup.new_tag("a")
anchor["href"] = "#" + anchor_tag
anchor["class"] = "link"
icon = soup.new_tag("i")
icon["data-feather"] = "link"
anchor.append(icon)
Expand Down
2 changes: 1 addition & 1 deletion code/templates/entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>{{ number }} {{ entity}}</h1>
<div class="card fluid error deprecation">
<p>
<mark class="secondary">DEPRECATED
<a href="/IFC/RELEASE/IFC4x3/HTML/content/terms_and_definitions.htm#3.1.30-deprecation"><i data-feather=link></i></a></mark>
<a href="/IFC/RELEASE/IFC4x3/HTML/content/terms_and_definitions.htm#deprecation"><i data-feather=link></i></a></mark>
This definition will be removed in a future major release of this standard
</p>
</div>
Expand Down
Loading

0 comments on commit ffbe9a2

Please sign in to comment.