<commit_before>package wikifier

import (
	"strconv"
	"strings"
)

type secBlock struct {
	n           int
	isIntro     bool
	headerLevel int
	*parserBlock
}

func newSecBlock(name string, b *parserBlock) block {
	return &secBlock{parserBlock: b}
}

func (sec *secBlock) parse(page *Page) {

	// wiki option
	enable := page.Opt.Page.EnableTitle

	// overwrite with local var if present
	val, _ := page.Get("page.enable.title")
	if boolVal, ok := val.(bool); ok {
		enable = boolVal
	}

	// @page.enable.title causes the first header to be larger than the
	// rest. it also uses @page.title as the first header if no other text
	// is provided.
	sec.n = page.sectionN
	sec.isIntro = sec.n == 0 && enable
	page.sectionN++

	// find the level from the parent section
	level := 1
	var blk block = sec
	for blk != nil {
		if parentSec, ok := blk.parentBlock().(*secBlock); ok {
			level = parentSec.headerLevel + 1
			break
		}
		blk = blk.parentBlock()
	}

	// top-level headers start at h2 when @page.enable.title is true, since the
	// page title is the sole h1. otherwise, h1 is top-level.
	if enable && level == 1 {
		level++
	}

	// intro is always h1
	if sec.isIntro {
		level = 1
	}

	// max is h6
	if level > 6 {
		level = 6
	}

	sec.headerLevel = level

	// this must come last so the section order is correct
	sec.parserBlock.parse(page)
}

func (sec *secBlock) html(page *Page, el element) {
	// HEADING

	// determine if this is the intro section
	typ := "section-title"
	level := sec.headerLevel
	if sec.isIntro {
		typ = "section-page-title"
	}

	// use the page title if no other title is provided and @page.enable.title
	title, fmtTitle := sec.blockName(), HTML("")
	if sec.isIntro && title == "" {
		title = page.Title()
		fmtTitle = page.FmtTitle()
	}

	// we have a title
	if title != "" {

		// format title if we still need to
		if fmtTitle == "" {
			fmtTitle = page.formatTextOpts(title, fmtOpt{pos: sec.openPos})
		}

		// TODO: meta section heading ID<commit_msg>sec not section<commit_after>package wikifier

import (
	"strconv"
	"strings"
)

type secBlock struct {
	n           int
	isIntro     bool
	headerLevel int
	*parserBlock
}

func newSecBlock(name string, b *parserBlock) block {
	return &secBlock{parserBlock: b}
}

func (sec *secBlock) parse(page *Page) {

	// wiki option
	enable := page.Opt.Page.EnableTitle

	// overwrite with local var if present
	val, _ := page.Get("page.enable.title")
	if boolVal, ok := val.(bool); ok {
		enable = boolVal
	}

	// @page.enable.title causes the first header to be larger than the
	// rest. it also uses @page.title as the first header if no other text
	// is provided.
	sec.n = page.sectionN
	sec.isIntro = sec.n == 0 && enable
	page.sectionN++

	// find the level from the parent section
	level := 1
	var blk block = sec
	for blk != nil {
		if parentSec, ok := blk.parentBlock().(*secBlock); ok {
			level = parentSec.headerLevel + 1
			break
		}
		blk = blk.parentBlock()
	}

	// top-level headers start at h2 when @page.enable.title is true, since the
	// page title is the sole h1. otherwise, h1 is top-level.
	if enable && level == 1 {
		level++
	}

	// intro is always h1
	if sec.isIntro {
		level = 1
	}

	// max is h6
	if level > 6 {
		level = 6
	}

	sec.headerLevel = level

	// this must come last so the section order is correct
	sec.parserBlock.parse(page)
}

func (sec *secBlock) html(page *Page, el element) {
	// HEADING

	// determine if this is the intro section
	typ := "sec-title"
	level := sec.headerLevel
	if sec.isIntro {
		typ = "sec-page-title"
	}

	// use the page title if no other title is provided and @page.enable.title
	title, fmtTitle := sec.blockName(), HTML("")
	if sec.isIntro && title == "" {
		title = page.Title()
		fmtTitle = page.FmtTitle()
	}

	// we have a title
	if title != "" {

		// format title if we still need to
		if fmtTitle == "" {
			fmtTitle = page.formatTextOpts(title, fmtOpt{pos: sec.openPos})
		}

		// TODO: meta section heading ID
{'fraction_non_alphanumeric': 0.1226653205451792, 'fraction_numerical': 0.006057546693589096, 'mean_word_length': 2.881488736532811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5659990', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1364, 'n_words': 465}