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

pkgname=marker
pkgver=2023.05.02
pkgrel=1
pkgdesc='Simple yet robust Markdown editor made with GTK'
arch=('x86_64')
url='https://fabiocolacio.github.io/Marker/'
license=('GPL3')
depends=('gtksourceview3' 'gtkspell3' 'webkit2gtk-4.1')
makedepends=('git' 'meson' 'itstool')
optdepends=('mathjax2: alternative backend for rendering formulas'
            'pandoc: export to RTF, ODT, DOCX')
_commit=454275255327cdd436e6f4669381c6dcb25fffc7
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 -c protocol.file.allow=always submodule update

  # Remove optimalization as it breaks charter
  export CFLAGS=${CFLAGS/ -O2}
 
  # Unbundle mathjax
  sed -i 's|file:///usr/share/javascript/mathjax/MathJax.js|file:///usr/share/mathjax2/MathJax.js|' src/marker-markdown.c

  cd src/scidown
  git submodule init
  git submodule set-url src/charter "$srcdir/charter"
  git -c protocol.file.allow=always submodule update

  cd src/charter
  git submodule init
  git submodule set-url src/tinyexpr "$srcdir/tinyexpr"
  git -c protocol.file.allow=always submodule update
}

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

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