Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pandoc Include Code Files
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
b3
Pandoc Include Code Files
Commits
8130a782
Commit
8130a782
authored
2 years ago
by
Bruno BEAUFILS
Browse files
Options
Downloads
Patches
Plain Diff
Simplify Makefile
parent
89009c06
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Makefile
+34
-97
34 additions, 97 deletions
Makefile
with
34 additions
and
97 deletions
Makefile
+
34
−
97
View file @
8130a782
# Name of the filter file, *with* `.lua` file extension.
FILTER_FILE
:=
$(
wildcard
*
.lua
)
# Name of the filter, *without* `.lua` file extension
FILTER_NAME
=
$(
patsubst %.lua,%,
$(
FILTER_FILE
))
# Allow to use a different pandoc binary, e.g. when testing.
# Allow to use a different pandoc binary, e.g. when testing
PANDOC
?=
pandoc
# Allow to adjust the diff command if necessary
DIFF
=
diff
# Use a POSIX sed with ERE ('v' is specific to GNU sed)
SED
:=
sed
$(
shell
sed
v </dev/null
>
/dev/null 2>&1
&&
echo
" --posix"
)
-E
# Name of the filter file, *with* `.lua` file extension
FILTER_FILE
:=
$(
wildcard
*
.lua
)
# Name of the filter, *without* `.lua` file extension
FILTER_NAME
=
$(
patsubst %.lua,%,
$(
FILTER_FILE
))
# Directory containing the Quarto extension
QUARTO_EXT_DIR
=
_extensions/
$(
FILTER_NAME
)
# The extension's name. Used in the Quarto extension metadata
EXT_NAME
=
$(
FILTER_NAME
)
# Current version, i.e., the latest tag. Used to version the quarto
# extension
.
#
Current version (the latest tag). Used for quarto
extension
VERSION
=
$(
shell git tag
--sort
=
-version
:refname
--merged
|
head
-n1
|
\
sed
-e
's/^v//'
|
tr
-d
"
\n
"
)
ifeq
"$(VERSION)" ""
VERSION
=
0.0.0
endif
# GitHub repository; used to setup the filter
.
# GitHub repository; used to setup the filter
REPO_PATH
=
$(
shell git remote get-url origin |
sed
-e
's%.*github\.com[/:]%%'
)
REPO_NAME
=
$(
shell git remote get-url origin |
sed
-e
's%.*/%%'
)
USER_NAME
=
$(
shell git config user.name
)
# Test that running the filter on the sample input document yields
# the expected output.
#
# The automatic variable `$<` refers to the first dependency
# (i.e., the filter file).
## Show available targets
# Comments preceding "simple" targets (those which do not user macro
# name) and introduced by two dashes are used as their describtion.
.PHONY
:
help
help
:
@
tabs 22
;
$(
SED
)
-ne
\
'/^## / h ; /^[^.$$#][^ ]+:/ { G; s/^(.*):.*##(.*)/\1@\2/; P ; h }'
\
$(
MAKEFILE_LIST
)
|
tr
@
'\t'
## Test that running the filter on the sample input yields expected output
.PHONY
:
test
test
:
$(FILTER_FILE) test/input.md test/test.yaml
$(
PANDOC
)
--defaults
test
/test.yaml |
\
$(
DIFF
)
test
/expected.native -
# Ensure that the `test` target is run each time it's called.
.PHONY
:
test
# Re-generate the expected output. This file **must not** be a
# dependency of the `test` target, as that would cause it to be
# regenerated on each run, making the test pointless.
## Re-generate the expected test output
# This file **must not** be a dependency of the `test` target, as that
# would cause it to be regenerated on each run, making the test
# pointless.
test/expected.native
:
$(FILTER_FILE) test/input.md test/test.yaml
$(
PANDOC
)
--defaults
test
/test.yaml
--output
=
$@
#
# Website
#
.PHONY
:
website
website
:
_site/index.html _site/$(FILTER_FILE)
_site/index.html
:
README.md test/input.md $(FILTER_FILE) .tools/docs.lua
\
_site/output.md _site/style.css
@
mkdir
-p
_site
$(
PANDOC
)
\
--standalone
\
--lua-filter
=
.tools/docs.lua
\
--metadata
=
sample-file:test/input.md
\
--metadata
=
result-file:_site/output.md
\
--metadata
=
code-file:
$(
FILTER_FILE
)
\
--css
=
style.css
\
--toc
\
--output
=
$@
$<
_site/style.css
:
@
mkdir
-p
_site
curl
\
--output
$@
\
'https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.css'
_site/output.md
:
$(FILTER_FILE) test/input.md test/test.yaml
@
mkdir
-p
_site
$(
PANDOC
)
\
--defaults
=
test
/test.yaml
\
--to
=
markdown
\
--output
=
$@
_site/$(FILTER_FILE)
:
$(FILTER_FILE)
@
mkdir
-p
_site
(
cd
_site
&&
ln
-sf
../
$<
$<
)
#
# Quarto extension
#
# Creates or updates the quarto extension
## Creates or updates the quarto extension
.PHONY
:
quarto-extension
quarto-extension
:
$(QUARTO_EXT_DIR)/_extension.yml
\
$(QUARTO_EXT_DIR)/$(FILTER_FILE)
...
...
@@ -100,46 +70,13 @@ $(QUARTO_EXT_DIR)/_extension.yml: _extensions/$(FILTER_NAME)
@
printf
'version: %s\n'
"
$(
VERSION
)
"
>>
$@
@
printf
'contributes:\n filters:\n - %s\n'
$(
FILTER_FILE
)
>>
$@
## The filter file must be below the quarto _extensions folder: a
## symlink in the extension would not work due to the way in which
## quarto installs extensions.
$(QUARTO_EXT_DIR)/$(FILTER_FILE)
:
$(FILTER_FILE) $(QUARTO_EXT_DIR)
if
[
!
-L
$(
FILTER_FILE
)
]
;
then
\
mv
$(
FILTER_FILE
)
$(
QUARTO_EXT_DIR
)
/
$(
FILTER_FILE
)
&&
\
ln
-s
$(
QUARTO_EXT_DIR
)
/
$(
FILTER_FILE
)
$(
FILTER_FILE
);
\
fi
#
# Release
#
## Sets a new release
.PHONY
:
release
release
:
quarto-extension
git commit
-am
"Release
$(
FILTER_NAME
)
$(
VERSION
)
"
git tag v
$(
VERSION
)
-m
"
$(
FILTER_NAME
)
$(
VERSION
)
"
#
# Update filter name
#
.PHONY
:
update-name
update-name
:
sed
-i
''
-e
's/greetings/
$(
FILTER_NAME
)
/g'
README.md
sed
-i
''
-e
's/greetings/
$(
FILTER_NAME
)
/g'
test
/test.yaml
setup
:
git
mv
greetings.lua
$(
REPO_NAME
)
.lua
@
# Crude method to updates the examples and links; removes the
@
# template instructions from the README.
sed
-i
''
\
-e
's/greetings/
$(
REPO_NAME
)
/g'
\
-e
's#tarleb/lua-filter-template#
$(
REPO_PATH
)
#g'
\
-e
'/^\* \*/,/^\* \*/d'
\
README.md
sed
-i
''
-e
's/greetings/
$(
REPO_NAME
)
/g'
test
/test.yaml
sed
-i
''
-e
's/Albert Krewinkel/
$(
USER_NAME
)
/'
LICENSE
#
# Clean
#
## Clean unnecessary files
.PHONY
:
clean
clean
:
rm
-f
_site/output.md _site/index.html _site/style.css
rm
-f
*
~
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment