# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

TS_BINDINGS=( python )

DISTUTILS_EXT=1
DISTUTILS_OPTIONAL=1
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{12..15} )
inherit distutils-r1 tree-sitter-grammar

DESCRIPTION="Markdown grammar for Tree-sitter"
HOMEPAGE="https://github.com/tree-sitter-grammars/tree-sitter-markdown"
SRC_URI="https://github.com/tree-sitter-grammars/tree-sitter-markdown/archive/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~riscv ~x86"

RDEPEND="!dev-libs/tree-sitter-markdown-inline"

PATCHES=( "${FILESDIR}"/${P}-python.patch )

src_test() {
	pushd tree-sitter-markdown 2>/dev/null
	tree-sitter-grammar_src_test
	popd 2>/dev/null
	# Running the tests on markdown-inline requires extensions to be enabled, but
	# the parser generated by upstream does not include the extensions.
	# https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/136
	#cd ../tree-sitter-markdown-inline
	#tree-sitter-grammar_src_test

	use python && distutils-r1_src_test
}

python_test() {
	epytest bindings/python/tests
}
