using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using CommonMark; using CommonMark.Syntax; using UnityEngine.UI; using TMPro; using CustomUI.BeatSaber; using IPA.Utilities; namespace BSIPA_ModList.UI.ViewControllers { [RequireComponent(typeof(RectTransform))] public class MarkdownView : MonoBehaviour { private class TagTypeComponent : MonoBehaviour { internal BlockTag Tag; internal HeadingData hData; } private string markdown = ""; private bool mdDirty = false; public string Markdown { get => markdown; set { markdown = value; mdDirty = true; } } public RectTransform rectTransform => GetComponent(); private ScrollView scrView; private RectTransform content; private RectTransform viewport; private CommonMarkSettings settings; public MarkdownView() { settings = CommonMarkSettings.Default.Clone(); settings.AdditionalFeatures = CommonMarkAdditionalFeatures.All; settings.RenderSoftLineBreaksAsLineBreaks = false; settings.UriResolver = ResolveUri; } public Func HasEmbeddedImage; private string ResolveUri(string arg) { var name = arg.Substring(3); if (!arg.StartsWith("!::") && !arg.StartsWith("w::")) { // !:: means embedded, w:: means web // this block is for when neither is specified Logger.md.Debug($"Resolving nonspecific URI {arg}"); // check if its embedded if (HasEmbeddedImage != null && HasEmbeddedImage(arg)) return "!::" + arg; else return "w::" + arg; } Logger.md.Debug($"Resolved specific URI {arg}"); return arg; } protected void Awake() { /*view = GetComponent(); view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; view.vertical = true; view.horizontal = false; view.scrollSensitivity = 0f; view.inertia = true; view.movementType = ScrollRect.MovementType.Clamped; scrollbar = new GameObject("Scrollbar", typeof(RectTransform)).AddComponent(); scrollbar.transform.SetParent(transform); scrollbar.direction = Scrollbar.Direction.TopToBottom; scrollbar.interactable = true; view.verticalScrollbar = scrollbar;*/ gameObject.SetActive(false); var vpgo = new GameObject("Viewport"); viewport = vpgo.AddComponent(); viewport.SetParent(transform); viewport.localPosition = Vector2.zero; viewport.anchorMin = Vector2.zero; viewport.anchorMax = Vector2.one; viewport.anchoredPosition = new Vector2(.5f, .5f); viewport.sizeDelta = Vector2.zero; var vpmask = vpgo.AddComponent(); var vpim = vpgo.AddComponent(); // supposedly Mask needs an Image? vpmask.showMaskGraphic = false; vpim.color = Color.white; vpim.sprite = WhitePixel; vpim.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial; //view.viewport = viewport; content = new GameObject("Content Wrapper").AddComponent(); content.SetParent(viewport); var contentLayout = content.gameObject.AddComponent(); var contentFitter = content.gameObject.AddComponent(); contentFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; contentFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained; contentLayout.preferredWidth = contentLayout.minWidth = rectTransform.sizeDelta.x; // to be adjusted content.gameObject.AddComponent(); content.localPosition = Vector2.zero; content.anchorMin = new Vector2(.5f, .5f); content.anchorMax = new Vector2(.5f, .5f); content.anchoredPosition = Vector2.zero; //content.sizeDelta = Vector2.zero; //view.content = content; var pageUp = Instantiate(Resources.FindObjectsOfTypeAll