# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>

pkgname=marker
pkgver=2020.04.04.2
pkgrel=4
pkgdesc='Simple yet robust Markdown editor made with GTK'
arch=('x86_64')
url='https://fabiocolacio.github.io/Marker/'
license=('GPL3')
depends=('gtksourceview3' 'gtkspell3' 'webkit2gtk')
makedepends=('git' 'meson')
optdepends=('mathjax2: alternative backend for rendering formulas'
            'pandoc: export to RTF, ODT, DOCX')
_commit=90f2667611a5017840dced736fd1ea801930a45f  # tags/2020.04.04.2^0
source=("git+https://github.com/fabiocolacio/Marker.git#commit=$_commit"
        'git+https://github.com/Mandarancio/scidown.git'
        'git+https://github.com/Mandarancio/charter.git'
        'git+https://github.com/codeplea/tinyexpr.git')
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd Marker
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd Marker
  git submodule init
  git submodule set-url src/scidown "$srcdir/scidown"
  git submodule update

  # Remove optimalization as it breaks charter
  export CFLAGS=${CFLAGS/ -O2}
 
  # ELF file must be in lib
  git cherry-pick -n 135857107277648f9f0d762268ec687d556a67dc

  # Unbundle mathjax
  git cherry-pick -n 13bce947564a444ce825752a69110a55cf0f6774
  sed -i 's|file:///usr/share/javascript/mathjax/MathJax.js|file:///usr/share/mathjax2/MathJax.js|' src/marker-markdown.c

  # Fix PDF export
  git cherry-pick -n fd383f5f0596afbbb28bf5c54cfc2da37ec4379c

  # Make pandoc optional
  git cherry-pick -n 9e9bf85e1ec80a3cf54aaab416f6cdbf85080c36

  cd src/scidown
  git submodule init
  git submodule set-url src/charter "$srcdir/charter"
  git submodule update

  cd src/charter
  git submodule init
  git submodule set-url src/tinyexpr "$srcdir/tinyexpr"
  git submodule update

  # Fix PDF export when charter is used
  git cherry-pick -n 958d5f06707932b48f383c06a2554da2657d6c17
}

build() {
  arch-meson Marker build
  meson compile -C build
}

package() {
  DESTDIR="$pkgdir" meson install -C build
}
