# $Id$
# Maintainer: Luke Shumaker <lukeshu@lukeshu.com>
# Maintainer (arch:python-markdown): Kyle Keen <keenerd@gmail.com>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Andrew Antle <andrew dot antle at gmail dot com>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: Chaiwat Suttipongsakul <cwt at bashell dot com>


# Rational for inclusion in [libre]:
#  - required by libre/parabolaweb-utils
#  - required by pcr-testing/anki-ccbc


pkgbase=python-markdown
pkgname=('python-markdown' 'python2-markdown')
pkgbase=${pkgbase}2
pkgname=("${pkgname[@]/%/2}")
_pkgbasename=Markdown
pkgver=2.6.11
pkgrel=2
pkgrel+=.1
pkgdesc="Python implementation of John Gruber's Markdown."
arch=('any')
url='http://pypi.python.org/pypi/Markdown'
license=('BSD')
depends=('python')
makedepends=('python' 'python2' 'python-setuptools' 'python2-setuptools')
source=("https://files.pythonhosted.org/packages/source/M/$_pkgbasename/$_pkgbasename-$pkgver.tar.gz")
md5sums=('a67c1b2914f7d74eeede2ebe0fdae470')

build() {
  # bug in 2.4, some DOS line endings slipped in
  find "$_pkgbasename-$pkgver/" -name '*py' | xargs sed -i 's|\r||g'

  cp -r $_pkgbasename-$pkgver "$srcdir/python2-markdown"
  cd "$srcdir/python2-markdown"
  find "$srcdir/python2-markdown" -name '*py' | xargs sed -i 's|#!/usr/bin/env python$|&2|'
}

package_python-markdown2() {
  depends=('python')
  provides=("python-markdown=$pkgver")
  conflicts=('python-markdown')
  cd "$srcdir/$_pkgbasename-$pkgver"
  python3 setup.py install --root="$pkgdir" --optimize=0
  install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_python2-markdown2() {
  depends=('python2')
  provides=("python2-markdown=$pkgver")
  conflicts=('python2-markdown')
  cd "$srcdir/python2-markdown"
  python2 setup.py install --root="$pkgdir" --optimize=0
  mv "$pkgdir/usr/bin/markdown_py" "$pkgdir/usr/bin/markdown_py2"
  install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

check_python-markdown2() {
  [[ $(python -c "import markdown; print(markdown.version)") == "$pkgver" ]]
  [[ $(python -c "import markdown; print(markdown.markdown('*test*'))") == "<p><em>test</em></p>" ]]
}

check_python2-markdown2() {
  [[ $(python2 -c "import markdown; print(markdown.version)") == "$pkgver" ]]
  [[ $(python2 -c "import markdown; print(markdown.markdown('*test*'))") == "<p><em>test</em></p>" ]]
}

