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

Fix some issues with code blocks and listing of source files #576

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 75 additions & 61 deletions ford/css/pygments.css
Original file line number Diff line number Diff line change
@@ -1,61 +1,75 @@
pre .hll { background-color: #ffffcc }
pre .c { color: #408080; font-style: italic } /* Comment */
pre .err { border: 1px solid #FF0000 } /* Error */
pre .k { color: #008000; font-weight: bold } /* Keyword */
pre .o { color: #666666 } /* Operator */
pre .cm { color: #408080; font-style: italic } /* Comment.Multiline */
pre .cp { color: #BC7A00 } /* Comment.Preproc */
pre .c1 { color: #408080; font-style: italic } /* Comment.Single */
pre .cs { color: #408080; font-style: italic } /* Comment.Special */
pre .gd { color: #A00000 } /* Generic.Deleted */
pre .ge { font-style: italic } /* Generic.Emph */
pre .gr { color: #FF0000 } /* Generic.Error */
pre .gh { color: #000080; font-weight: bold } /* Generic.Heading */
pre .gi { color: #00A000 } /* Generic.Inserted */
pre .go { color: #888888 } /* Generic.Output */
pre .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
pre .gs { font-weight: bold } /* Generic.Strong */
pre .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
pre .gt { color: #0044DD } /* Generic.Traceback */
pre .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
pre .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
pre .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
pre .kp { color: #008000 } /* Keyword.Pseudo */
pre .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
pre .kt { color: #B00040 } /* Keyword.Type */
pre .m { color: #666666 } /* Literal.Number */
pre .s { color: #BA2121 } /* Literal.String */
pre .na { color: #7D9029 } /* Name.Attribute */
pre .nb { color: #008000 } /* Name.Builtin */
pre .nc { color: #0000FF; font-weight: bold } /* Name.Class */
pre .no { color: #880000 } /* Name.Constant */
pre .nd { color: #AA22FF } /* Name.Decorator */
pre .ni { color: #999999; font-weight: bold } /* Name.Entity */
pre .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
pre .nf { color: #0000FF } /* Name.Function */
pre .nl { color: #A0A000 } /* Name.Label */
pre .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
pre .nt { color: #008000; font-weight: bold } /* Name.Tag */
pre .nv { color: #19177C } /* Name.Variable */
pre .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
pre .w { color: #bbbbbb } /* Text.Whitespace */
pre .mf { color: #666666 } /* Literal.Number.Float */
pre .mh { color: #666666 } /* Literal.Number.Hex */
pre .mi { color: #666666 } /* Literal.Number.Integer */
pre .mo { color: #666666 } /* Literal.Number.Oct */
pre .sb { color: #BA2121 } /* Literal.String.Backtick */
pre .sc { color: #BA2121 } /* Literal.String.Char */
pre .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
pre .s2 { color: #BA2121 } /* Literal.String.Double */
pre .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
pre .sh { color: #BA2121 } /* Literal.String.Heredoc */
pre .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
pre .sx { color: #008000 } /* Literal.String.Other */
pre .sr { color: #BB6688 } /* Literal.String.Regex */
pre .s1 { color: #BA2121 } /* Literal.String.Single */
pre .ss { color: #19177C } /* Literal.String.Symbol */
pre .bp { color: #008000 } /* Name.Builtin.Pseudo */
pre .vc { color: #19177C } /* Name.Variable.Class */
pre .vg { color: #19177C } /* Name.Variable.Global */
pre .vi { color: #19177C } /* Name.Variable.Instance */
pre .il { color: #666666 } /* Literal.Number.Integer.Long */
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.codehilite .hll { background-color: #ffffcc }
.codehilite { background: #f8f8f8; }
.codehilite .c { color: #3D7B7B; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #FF0000 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #666666 } /* Operator */
.codehilite .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
.codehilite .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #9C6500 } /* Comment.Preproc */
.codehilite .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
.codehilite .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.codehilite .gr { color: #E40000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #008400 } /* Generic.Inserted */
.codehilite .go { color: #717171 } /* Generic.Output */
.codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0044DD } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #008000 } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #B00040 } /* Keyword.Type */
.codehilite .m { color: #666666 } /* Literal.Number */
.codehilite .s { color: #BA2121 } /* Literal.String */
.codehilite .na { color: #687822 } /* Name.Attribute */
.codehilite .nb { color: #008000 } /* Name.Builtin */
.codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.codehilite .no { color: #880000 } /* Name.Constant */
.codehilite .nd { color: #AA22FF } /* Name.Decorator */
.codehilite .ni { color: #717171; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #0000FF } /* Name.Function */
.codehilite .nl { color: #767600 } /* Name.Label */
.codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #19177C } /* Name.Variable */
.codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mb { color: #666666 } /* Literal.Number.Bin */
.codehilite .mf { color: #666666 } /* Literal.Number.Float */
.codehilite .mh { color: #666666 } /* Literal.Number.Hex */
.codehilite .mi { color: #666666 } /* Literal.Number.Integer */
.codehilite .mo { color: #666666 } /* Literal.Number.Oct */
.codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
.codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
.codehilite .sc { color: #BA2121 } /* Literal.String.Char */
.codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
.codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
.codehilite .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
.codehilite .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
.codehilite .sx { color: #008000 } /* Literal.String.Other */
.codehilite .sr { color: #A45A77 } /* Literal.String.Regex */
.codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
.codehilite .ss { color: #19177C } /* Literal.String.Symbol */
.codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
.codehilite .fm { color: #0000FF } /* Name.Function.Magic */
.codehilite .vc { color: #19177C } /* Name.Variable.Class */
.codehilite .vg { color: #19177C } /* Name.Variable.Global */
.codehilite .vi { color: #19177C } /* Name.Variable.Instance */
.codehilite .vm { color: #19177C } /* Name.Variable.Magic */
.codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */
16 changes: 8 additions & 8 deletions ford/fortran_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import os
import toposort
from itertools import chain, product
from typing import List, Optional, Union, Dict
from typing import List, Optional, Union, Dict, Set
from pathlib import Path
from fnmatch import fnmatch

Expand Down Expand Up @@ -84,7 +84,7 @@
}


def find_all_files(settings: ProjectSettings) -> List[Path]:
def find_all_files(settings: ProjectSettings) -> Set[Path]:
"""Returns a list of all selected files below a set of directories"""

file_extensions = chain(
Expand All @@ -94,16 +94,16 @@ def find_all_files(settings: ProjectSettings) -> List[Path]:
)

# Get initial list of all files in all source directories
src_files: List[Path] = []
src_files: Set[Path] = set()

for src_dir, extension in product(settings.src_dir, file_extensions):
src_files.extend(Path(src_dir).glob(f"**/*.{extension}"))
src_files.update(Path(src_dir).glob(f"**/*.{extension}"))

# Remove files under excluded directories
for exclude_dir in settings.exclude_dir:
src_files = [
src_files = {
src for src in src_files if not fnmatch(str(src), f"{exclude_dir}/*")
]
}

bottom_level_dirs = [src_dir.name for src_dir in settings.src_dir]
# First, let's check if the files are relative paths or not
Expand All @@ -122,9 +122,9 @@ def find_all_files(settings: ProjectSettings) -> List[Path]:
settings.exclude[i] = glob_exclude

for exclude in settings.exclude:
src_files = [
src_files = {
src for src in src_files if not fnmatch(os.path.relpath(src), exclude)
]
}

return src_files

Expand Down
14 changes: 11 additions & 3 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ def markdown(self, md: MetaMarkdown):
re.IGNORECASE | re.DOTALL | re.MULTILINE,
)
if match := regex.search(self.source_file.raw_src):
self.src = highlight(match.group(), FortranLexer(), HtmlFormatter())
self.src = highlight(
match.group(),
FortranLexer(),
HtmlFormatter(cssclass="hl codehilite"),
)
else:
self.src = ""
if self.settings.warn:
Expand Down Expand Up @@ -1544,7 +1548,9 @@ def __init__(
self.raw_src = pathlib.Path(self.path).read_text(encoding=settings.encoding)
lexer = FortranFixedLexer() if self.fixed else FortranLexer()
self.src = highlight(
self.raw_src, lexer, HtmlFormatter(lineanchors="ln", cssclass="hl")
self.raw_src,
lexer,
HtmlFormatter(lineanchors="ln", cssclass="hl codehilite"),
)

@property
Expand Down Expand Up @@ -2704,7 +2710,9 @@ def __init__(self, filename: PathLike, settings: ProjectSettings):

lexer = getattr(pygments.lexers, extra_filetypes.lexer)
self.src = highlight(
self.raw_src, lexer, HtmlFormatter(lineanchors="ln", cssclass="hl")
self.raw_src,
lexer,
HtmlFormatter(lineanchors="ln", cssclass="hl codehilite"),
)

self.comment = extra_filetypes.comment
Expand Down
2 changes: 1 addition & 1 deletion ford/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<li class="nav-item"><a class="nav-link" href="{{ pages.url }}">{{ pages.title }}</a></li>
{% endif %}
{% if incl_src %}
{% if project.files|length + project.extra_files|length is more_than_one %}
{% if (project.files|length + project.extra_files|length) is more_than_one %}
<li class="nav-item">
<a class="nav-link" href="{{ project_url }}/lists/files.html">Source Files</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion ford/templates/info_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h1>{{ page.title }}</h1>
</div>
{% endif %}

<div class="col" id='text'>
<div class="col-9" id='text'>
{{ page.contents }}
</div>
</div>
Expand Down