Browse Source

Added block quote support

pull/11/head
Anairkoen Schno 5 years ago
parent
commit
8ad3986d70
2 changed files with 76 additions and 13 deletions
  1. +20
    -4
      BSIPA-ModList/README.md
  2. +56
    -9
      BSIPA-ModList/UI/ViewControllers/MarkdownView.cs

+ 20
- 4
BSIPA-ModList/README.md View File

@ -8,6 +8,8 @@ Find all builds in [AppVeyor](https://ci.appveyor.com/project/nike4613/beatsaber
### This test header contains a `code` block
[Test ref item]: https://www.google.com/ "with title text"
1. And here is a
list
2. Test
@ -15,12 +17,26 @@ Find all builds in [AppVeyor](https://ci.appveyor.com/project/nike4613/beatsaber
- 2
- 3
>This is a block quote
[Test ref item] is a ref instance (?)
> This is a block quote
>
> This will be supported soon....
>
> > This is a nested block quote
> >
> > ***
> >
> > more content
>
>This will be supported soon....
> more content
```
This is a code block...
This is a fenced code block...
This will be supported soon....
```
```
this is an indented code block
this will also be supported soon

+ 56
- 9
BSIPA-ModList/UI/ViewControllers/MarkdownView.cs View File

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using CommonMark;
using CommonMark.Syntax;
@ -208,6 +206,30 @@ namespace BSIPA_ModList.UI.ViewControllers
}
}
private static Sprite blockQuoteBackground;
private static Sprite BlockQuoteBackground
{
get
{
if (blockQuoteBackground == null)
blockQuoteBackground = Resources.FindObjectsOfTypeAll<Sprite>().First(s => s.name == "RoundRectNormal");
return blockQuoteBackground;
}
}
private static Sprite blockQuoteSidebar;
private static Sprite BlockQuoteSidebar
{
get
{
if (blockQuoteSidebar == null)
blockQuoteSidebar = Resources.FindObjectsOfTypeAll<Sprite>().First(s => s.name == "BackButtonBG");
return blockQuoteSidebar;
}
}
private static readonly Color BlockQuoteColor = new Color(30f/255, 109f/255, 178f/255, .25f);
#if DEBUG
#if UI_CONFIGURE_MARKDOWN_THEMATIC_BREAK
private byte tbreakSettings = 0;
@ -261,6 +283,7 @@ namespace BSIPA_ModList.UI.ViewControllers
const float BreakHeight = .5f;
const int TextInset = 1;
const int BlockQuoteInset = TextInset * 2;
void Spacer(float size = 1.5f)
{
@ -276,7 +299,7 @@ namespace BSIPA_ModList.UI.ViewControllers
l.minHeight = l.preferredHeight = size;
}
HorizontalOrVerticalLayoutGroup BlockNode(string name, float spacing, bool isVertical, Action<TagTypeComponent> apply = null, float? spacer = null, bool isDoc = false, bool matchWidth = false)
HorizontalOrVerticalLayoutGroup BlockNode(string name, float spacing, bool isVertical, Action<TagTypeComponent> apply = null, float? spacer = null, bool isDoc = false, bool matchWidth = false, float matchWidthDiff = 0f)
{
if (node.IsOpening)
{
@ -298,7 +321,7 @@ namespace BSIPA_ModList.UI.ViewControllers
vlayout.anchorMax = new Vector2(1f, 1f);
}
if (matchWidth)
vlayout.sizeDelta = new Vector2(layout.Peek().rect.width, BreakHeight);
vlayout.sizeDelta = new Vector2(layout.Peek().rect.width-matchWidthDiff, 0f);
var tt = go.AddComponent<TagTypeComponent>();
tt.Tag = block.Tag;
@ -312,14 +335,12 @@ namespace BSIPA_ModList.UI.ViewControllers
l = go.AddComponent<HorizontalLayoutGroup>();
l.childControlHeight = l.childControlWidth = true;
l.childForceExpandHeight = l.childForceExpandWidth = false;
l.childForceExpandHeight = false;
l.childForceExpandWidth = isDoc;
l.spacing = spacing;
if (isDoc)
{
vlayout.anchoredPosition = new Vector2(0f, -vlayout.rect.height);
}
return l;
}
@ -334,7 +355,7 @@ namespace BSIPA_ModList.UI.ViewControllers
return null;
}
void ThematicBreak(float spacerSize = 1f)
void ThematicBreak(float spacerSize = 1.5f)
{ // TODO: Fix positioning
var go = new GameObject("ThematicBreak", typeof(RectTransform), typeof(HorizontalLayoutGroup));
var vlayout = go.GetComponent<RectTransform>();
@ -398,7 +419,7 @@ namespace BSIPA_ModList.UI.ViewControllers
l.padding = new RectOffset(TextInset, TextInset, 0, 0);
}
else
ThematicBreak(1.5f);
ThematicBreak(2f);
break;
case BlockTag.AtxHeading:
l = BlockNode("AtxHeading", .1f, false, t => t.hData = block.Heading);
@ -414,6 +435,32 @@ namespace BSIPA_ModList.UI.ViewControllers
ThematicBreak();
break;
// TODO: add the rest of the tag types
case BlockTag.BlockQuote:
l = BlockNode("BlockQuote", .1f, true, matchWidth: true, matchWidthDiff: BlockQuoteInset*2, spacer: 1.5f);
if (l)
{
l.childForceExpandWidth = true;
l.padding = new RectOffset(BlockQuoteInset, BlockQuoteInset, BlockQuoteInset, 0);
var go = l.gameObject;
var rt = go.GetComponent<RectTransform>();
var im = go.AddComponent<Image>();
im.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial;
im.type = Image.Type.Sliced;
im.sprite = Instantiate(BlockQuoteBackground);
im.color = BlockQuoteColor;
/*var im2 = go.AddComponent<Image>();
im2.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial;
im2.type = Image.Type.Sliced;
im2.sprite = Instantiate(BlockQuoteSidebar);*/
//im2.color = BlockQuoteColor;
}
break;
case BlockTag.ReferenceDefinition: // i have no idea what the state looks like here
block.DebugPrintTo(Logger.md.Info, 5);
break;
}
}
else if (node.Inline != null)


Loading…
Cancel
Save